-
Notifications
You must be signed in to change notification settings - Fork 14
/
script-set-option.php
87 lines (75 loc) · 3.97 KB
/
script-set-option.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require_once( 'libraries/workflows.php' );
require_once( 'functions.php' );
require_once( __DIR__ . '/init.php' );
$HOME = exec( 'echo $HOME' );
$data = DATA_DIR;
$config = simplexml_load_file( "$data/config/config.xml" );
$option = substr( $argv[1], 0, strpos( $argv[1], ':' ) );
$value = trim( str_replace( '\\', '', substr( $argv[1], strpos( $argv[1], ':' ) + 1 ) ) );
$w = new Workflows;
function setOption() {
global $data, $config, $option, $value, $w;
if ( empty( $value ) ) {
if ( isset( $config->$option ) && ( ! empty( $config->$option ) ) ) {
if ( $option == 'backups' ) {
$value = (int) $config->$option;
} else {
$value = $config->$option;
}
}
}
$options = array(
'authorName' => 'Please enter the name you use when you write workflows',
'packalAccount' => 'Do you have an account on Packal? Please answer yes or no.',
'username' => 'Please enter your Packal username',
'workflowReporting' => 'Would you like to send anonymous data about your installed workflows to Packal.org? Please enter yes or no.',
'backups' => 'Please enter the number of backups you would like to keep',
);
$bool = array( 'packalAccount', 'workflowReporting' );
if ( in_array( $option, $bool ) ) {
if ( $option == 'workflowReporting' ) {
if ( $config->workflowReporting == 1 ) {
$w->result( 'option-set-workflowReporting-1', 'option-set-workflowReporting-1', 'Send anonymous data to Packal.org.', 'Currently selected', 'assets/icons/svn-commit.png', 'yes', '' );
$w->result( 'option-set-workflowReporting-0', 'option-set-workflowReporting-0', 'Do not send anonymous data to Packal.org.', '', '', 'yes', '' );
} else {
$w->result( 'option-set-workflowReporting-1', 'option-set-workflowReporting-1', 'Send anonymous data to Packal.org.', '', 'assets/icons/svn-commit.png', 'yes', '' );
$w->result( 'option-set-workflowReporting-0', 'option-set-workflowReporting-0', 'Do not send anonymous data to Packal.org.', 'Currently selected', '', 'yes', '' );
}
} elseif ( $option == 'packalAccount' ) {
$w->result( 'option-set-packalAccount-1', 'option-set-packalAccount-1', 'I do have an account on Packal.org', '', '', 'yes', '' );
$w->result( 'option-set-packalAccount-0', 'option-set-packalAccount-0', 'I do not have an account on Packal.org', '', '', 'yes', '' );
}
} else {
if ( empty( $value ) ) {
$w->result( "option-set-$option-$value", "option-set-$option-$value", $options[ $option ], "$value", '', 'no', '' );
} elseif ( $option == 'backups' ) {
if ( ( $value > 9 ) || ( $value < 0 ) ) {
$w->result( "option-set-$option-$value", "option-set-$option-$value", 'Error: The number of backups must be positive and less than 10', '', '', 'no', '' );
} elseif ( ! is_numeric( $value ) ) {
$w->result( "option-set-$option-$value", "option-set-$option-$value", 'Error: The number of backups must be an integer', '', '', 'no', '' );
} else {
$value = (int) $value;
$w->result( "option-set-$option-$value", "option-set-$option-$value", "Set the number of backups to keep to '$value'", "$value", '', 'yes', '' );
}
} else {
if ( $option == 'username' ) {
if ( $config->packalAccount == 1 ) {
$w->result( '', "option-set-$option-$value", 'Set your ' . $option . " to '$value'", "$value", '', 'yes', '' );
$w->result( '', "option-set-$option-", 'Clear Packal Username', '', '', 'yes', '' );
}
} elseif ( $option == 'authorName' ) {
if ( empty( $config->authorName ) ) {
$w->result( '', "option-set-$option-$value", "Set your author name to '$value'", "$value", '', 'yes', '' );
} else {
$w->result( '', "option-set-$option-$value", "Set your author name to '$value'", "$value", '', 'yes', '' );
$w->result( '', "option-set-$option-", 'Clear Author Name', '', '', 'yes', '' );
}
} else {
$w->result( "option-set-$option-$value", "option-set-$option-$value", 'Set your ' . $option . " to '$value'", $value, '', 'yes', '' );
}
}
}
}
setOption();
echo $w->toxml();