| 16 | | var $tab_size = 4; |
|---|
| 17 | | var $_tab_strings = array(); |
|---|
| 18 | | var $operations = array |
|---|
| 19 | | ( |
|---|
| 20 | | 'newlines', |
|---|
| 21 | | 'tabs2spaces', |
|---|
| 22 | | 'open_pre_strip', |
|---|
| 23 | | 'close_post_strip', |
|---|
| 24 | | 'line_end_ws', |
|---|
| 25 | | ); |
|---|
| 26 | | |
|---|
| 27 | | /** |
|---|
| 28 | | * Calls all the normalization operations defined for given $data |
|---|
| 29 | | * |
|---|
| 30 | | * @param string $data data to normalize (usually file contents) |
|---|
| 31 | | * @return string normalized |
|---|
| 32 | | */ |
|---|
| 33 | | function normalize($data) |
|---|
| 34 | | { |
|---|
| 35 | | foreach($this->operations as $op) |
|---|
| 36 | | { |
|---|
| 37 | | if (!method_exists($this, $op)) |
|---|
| 38 | | { |
|---|
| 39 | | continue; |
|---|
| 40 | | } |
|---|
| 41 | | $data = $this->$op($data); |
|---|
| 42 | | } |
|---|
| 43 | | return $data; |
|---|
| 44 | | } |
|---|
| 45 | | |
|---|
| 46 | | /** |
|---|
| 47 | | * Normalizes various newline schemes to unix newlines |
|---|
| 48 | | * |
|---|
| 49 | | * @param string $data data to normalize (usually file contents) |
|---|
| 50 | | * @return string normalized |
|---|
| 51 | | */ |
|---|
| 52 | | function newlines($data) |
|---|
| 53 | | { |
|---|
| 54 | | return preg_replace("/\n\r|\r\n|\r/", "\n", $data); |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | /** |
|---|
| 58 | | * Normalizes tabs to given number of spaces |
|---|
| 59 | | * |
|---|
| 60 | | * @see $this->tab_size |
|---|
| 61 | | * @param string $data data to normalize (usually file contents) |
|---|
| 62 | | * @return string normalized |
|---|
| 63 | | */ |
|---|
| 64 | | function tabs2spaces($data) |
|---|
| 65 | | { |
|---|
| 66 | | if (!isset($this->_tab_strings[$this->tab_size])) |
|---|
| 67 | | { |
|---|
| 68 | | $this->_tab_strings[$this->tab_size] = str_pad('', $this->tab_size, ' '); |
|---|
| 69 | | } |
|---|
| 70 | | return str_replace("\t", $this->_tab_strings[$this->tab_size], $data); |
|---|
| 71 | | } |
|---|
| 72 | | |
|---|
| 73 | | /** |
|---|
| 74 | | * Removes whitespace between start of string and first PHP open |
|---|
| 75 | | * tag (if said tag is the first nonwhitespace in string) |
|---|
| 76 | | * |
|---|
| 77 | | * @param string $data data to normalize (usually file contents) |
|---|
| 78 | | * @return string normalized |
|---|
| 79 | | */ |
|---|
| 80 | | function open_pre_strip($data) |
|---|
| 81 | | { |
|---|
| 82 | | return preg_replace('%^\s+(<\?(php)?)%s', '\\1', $data); |
|---|
| 83 | | } |
|---|
| 84 | | |
|---|
| 85 | | /** |
|---|
| 86 | | * Removes whitespace between last PHP close tag and end of |
|---|
| 87 | | * string (if said tag is the last nonwhitespace in the string) |
|---|
| 88 | | * |
|---|
| 89 | | * @param string $data data to normalize (usually file contents) |
|---|
| 90 | | * @return string normalized |
|---|
| 91 | | */ |
|---|
| 92 | | function close_post_strip($data) |
|---|
| 93 | | { |
|---|
| 94 | | return preg_replace('%(\?>)\s+$%s', '\\1', $data); |
|---|
| 95 | | } |
|---|
| 96 | | |
|---|
| 97 | | /** |
|---|
| 98 | | * Removes whitespace from ends of lines (if lines are not all whitespace) |
|---|
| 99 | | * |
|---|
| 100 | | * @param string $data data to normalize (usually file contents) |
|---|
| 101 | | * @return string normalized |
|---|
| 102 | | */ |
|---|
| 103 | | function line_end_ws($data) |
|---|
| 104 | | { |
|---|
| 105 | | return $data; |
|---|
| 106 | | /* Not so easy afterall |
|---|
| 107 | | $data_arr = explode("\n", $data); |
|---|
| 108 | | //$data_arr = preg_replace('%[\t\f ]+$%m', '', $data_arr); |
|---|
| 109 | | $data_arr = preg_replace('%(^\s+$)|([^\t\f ])\s+%', '\\1', $data_arr); |
|---|
| 110 | | return implode("\n", $data_arr); |
|---|
| 111 | | */ |
|---|
| 112 | | } |
|---|
| 113 | | |
|---|
| | 18 | echo "\nInitialization failed\n\n"; |
|---|
| | 19 | exit(1); |
|---|
| | 20 | } |
|---|
| | 21 | mgd_auth_midgard($username, $password); |
|---|
| | 22 | if (!$_MIDGARD['user']) |
|---|
| | 23 | { |
|---|
| | 24 | echo "\nAuthentication failed\n\n"; |
|---|
| | 25 | exit(1); |
|---|
| | 26 | } |
|---|
| | 27 | if (!$_MIDGARD['sitegroup'] === 0) |
|---|
| | 28 | { |
|---|
| | 29 | echo "\nSG0 usage not supported\n\n"; |
|---|
| | 30 | exit(1); |
|---|