@@ -2,139 +2,139 @@ |
||
2 | 2 | |
3 | 3 | class Nip_Collection implements Countable, IteratorAggregate, ArrayAccess |
4 | 4 | { |
5 | - protected $_items = array(); |
|
6 | - protected $_index = 0; |
|
7 | - |
|
8 | - public function __construct($items = array()) |
|
9 | - { |
|
10 | - if (is_array($items)) { |
|
11 | - $this->_items = $items; |
|
12 | - } elseif ($items instanceof Nip_Collection) { |
|
13 | - $this->_items = $items->toArray(); |
|
14 | - } |
|
15 | - } |
|
16 | - |
|
17 | - public function count() |
|
18 | - { |
|
19 | - return count($this->_items); |
|
20 | - } |
|
21 | - |
|
22 | - public function getIterator() |
|
23 | - { |
|
24 | - return new ArrayIterator($this->_items); |
|
25 | - } |
|
26 | - |
|
27 | - public function offsetExists($index) |
|
28 | - { |
|
29 | - return in_array($index, array_keys($this->_items)); |
|
30 | - } |
|
31 | - |
|
32 | - public function exists($index) |
|
33 | - { |
|
34 | - return $this->offsetExists($index); |
|
35 | - } |
|
36 | - |
|
37 | - public function offsetGet($index) |
|
38 | - { |
|
39 | - return $this->offsetExists($index) ? $this->_items[$index] : null; |
|
40 | - } |
|
41 | - |
|
42 | - public function offsetSet($index, $value) |
|
43 | - { |
|
44 | - if (is_null($index)) { |
|
45 | - $index = $this->_index++; |
|
46 | - } |
|
47 | - $this->_items[$index] = $value; |
|
48 | - } |
|
49 | - |
|
50 | - public function offsetUnset($index) |
|
51 | - { |
|
52 | - if ($this->offsetExists($index)) { |
|
53 | - unset($this->_items[$index]); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - public function rewind() |
|
58 | - { |
|
59 | - $this->_index = 0; |
|
60 | - return reset($this->_items); |
|
61 | - } |
|
62 | - |
|
63 | - public function end() |
|
64 | - { |
|
65 | - $this->_index = count($this->_items); |
|
66 | - return end($this->_items); |
|
67 | - } |
|
68 | - |
|
69 | - public function current() |
|
70 | - { |
|
71 | - return current($this->_items); |
|
72 | - } |
|
73 | - |
|
74 | - public function next() |
|
75 | - { |
|
76 | - $this->_index++; |
|
77 | - return next($this->_items); |
|
78 | - } |
|
5 | + protected $_items = array(); |
|
6 | + protected $_index = 0; |
|
7 | + |
|
8 | + public function __construct($items = array()) |
|
9 | + { |
|
10 | + if (is_array($items)) { |
|
11 | + $this->_items = $items; |
|
12 | + } elseif ($items instanceof Nip_Collection) { |
|
13 | + $this->_items = $items->toArray(); |
|
14 | + } |
|
15 | + } |
|
16 | + |
|
17 | + public function count() |
|
18 | + { |
|
19 | + return count($this->_items); |
|
20 | + } |
|
21 | + |
|
22 | + public function getIterator() |
|
23 | + { |
|
24 | + return new ArrayIterator($this->_items); |
|
25 | + } |
|
26 | + |
|
27 | + public function offsetExists($index) |
|
28 | + { |
|
29 | + return in_array($index, array_keys($this->_items)); |
|
30 | + } |
|
31 | + |
|
32 | + public function exists($index) |
|
33 | + { |
|
34 | + return $this->offsetExists($index); |
|
35 | + } |
|
36 | + |
|
37 | + public function offsetGet($index) |
|
38 | + { |
|
39 | + return $this->offsetExists($index) ? $this->_items[$index] : null; |
|
40 | + } |
|
41 | + |
|
42 | + public function offsetSet($index, $value) |
|
43 | + { |
|
44 | + if (is_null($index)) { |
|
45 | + $index = $this->_index++; |
|
46 | + } |
|
47 | + $this->_items[$index] = $value; |
|
48 | + } |
|
49 | + |
|
50 | + public function offsetUnset($index) |
|
51 | + { |
|
52 | + if ($this->offsetExists($index)) { |
|
53 | + unset($this->_items[$index]); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + public function rewind() |
|
58 | + { |
|
59 | + $this->_index = 0; |
|
60 | + return reset($this->_items); |
|
61 | + } |
|
62 | + |
|
63 | + public function end() |
|
64 | + { |
|
65 | + $this->_index = count($this->_items); |
|
66 | + return end($this->_items); |
|
67 | + } |
|
68 | + |
|
69 | + public function current() |
|
70 | + { |
|
71 | + return current($this->_items); |
|
72 | + } |
|
73 | + |
|
74 | + public function next() |
|
75 | + { |
|
76 | + $this->_index++; |
|
77 | + return next($this->_items); |
|
78 | + } |
|
79 | 79 | |
80 | - public function unshift($value, $index = false) |
|
81 | - { |
|
82 | - if (is_null($index)) { |
|
83 | - $index = $this->_index++; |
|
84 | - } |
|
85 | - |
|
86 | - $this->_items = array_reverse($this->_items, true); |
|
87 | - $this->_items[$index] = $value; |
|
88 | - $this->_items = array_reverse($this->_items, true); |
|
80 | + public function unshift($value, $index = false) |
|
81 | + { |
|
82 | + if (is_null($index)) { |
|
83 | + $index = $this->_index++; |
|
84 | + } |
|
85 | + |
|
86 | + $this->_items = array_reverse($this->_items, true); |
|
87 | + $this->_items[$index] = $value; |
|
88 | + $this->_items = array_reverse($this->_items, true); |
|
89 | 89 | |
90 | - return $this; |
|
91 | - } |
|
92 | - |
|
93 | - public function toArray() |
|
94 | - { |
|
95 | - $return = $this->_items; |
|
96 | - reset($return); |
|
97 | - return $return; |
|
98 | - } |
|
99 | - |
|
100 | - public function clear() |
|
101 | - { |
|
102 | - $this->rewind(); |
|
103 | - $this->_items = array(); |
|
104 | - |
|
105 | - return $this; |
|
106 | - } |
|
90 | + return $this; |
|
91 | + } |
|
92 | + |
|
93 | + public function toArray() |
|
94 | + { |
|
95 | + $return = $this->_items; |
|
96 | + reset($return); |
|
97 | + return $return; |
|
98 | + } |
|
99 | + |
|
100 | + public function clear() |
|
101 | + { |
|
102 | + $this->rewind(); |
|
103 | + $this->_items = array(); |
|
104 | + |
|
105 | + return $this; |
|
106 | + } |
|
107 | 107 | |
108 | - public function keys() |
|
109 | - { |
|
110 | - return array_keys($this->_items); |
|
111 | - } |
|
112 | - |
|
113 | - public function ksort() |
|
114 | - { |
|
115 | - ksort($this->_items); |
|
116 | - $this->rewind(); |
|
117 | - return $this; |
|
118 | - } |
|
119 | - |
|
120 | - public function usort($callback) |
|
121 | - { |
|
122 | - usort($this->_items, $callback); |
|
123 | - $this->rewind(); |
|
124 | - return $this; |
|
125 | - } |
|
126 | - |
|
127 | - public function uasort($callback) |
|
128 | - { |
|
129 | - uasort($this->_items, $callback); |
|
130 | - $this->rewind(); |
|
131 | - return $this; |
|
132 | - } |
|
133 | - |
|
134 | - public function shuffle() |
|
135 | - { |
|
136 | - shuffle($this->_items); |
|
137 | - $this->rewind(); |
|
138 | - return $this; |
|
139 | - } |
|
108 | + public function keys() |
|
109 | + { |
|
110 | + return array_keys($this->_items); |
|
111 | + } |
|
112 | + |
|
113 | + public function ksort() |
|
114 | + { |
|
115 | + ksort($this->_items); |
|
116 | + $this->rewind(); |
|
117 | + return $this; |
|
118 | + } |
|
119 | + |
|
120 | + public function usort($callback) |
|
121 | + { |
|
122 | + usort($this->_items, $callback); |
|
123 | + $this->rewind(); |
|
124 | + return $this; |
|
125 | + } |
|
126 | + |
|
127 | + public function uasort($callback) |
|
128 | + { |
|
129 | + uasort($this->_items, $callback); |
|
130 | + $this->rewind(); |
|
131 | + return $this; |
|
132 | + } |
|
133 | + |
|
134 | + public function shuffle() |
|
135 | + { |
|
136 | + shuffle($this->_items); |
|
137 | + $this->rewind(); |
|
138 | + return $this; |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |
@@ -5,44 +5,44 @@ |
||
5 | 5 | class Process |
6 | 6 | { |
7 | 7 | |
8 | - protected $_pid; |
|
9 | - protected $_command; |
|
10 | - |
|
11 | - public function __construct($command = false) |
|
12 | - { |
|
13 | - if ($command) { |
|
14 | - $this->_command = $command; |
|
15 | - } |
|
16 | - } |
|
17 | - |
|
18 | - public function run() |
|
19 | - { |
|
20 | - $command = "nohup $this->_command > /dev/null 2>&1 & echo $!"; |
|
21 | - $this->_pid = shell_exec($command); |
|
22 | - |
|
23 | - return $this; |
|
24 | - } |
|
25 | - |
|
26 | - public function running() |
|
27 | - { |
|
28 | - exec("ps -p $this->_pid", $output); |
|
29 | - return isset($output[1]); |
|
30 | - } |
|
31 | - |
|
32 | - public function stop() |
|
33 | - { |
|
34 | - exec("kill $this->_pid"); |
|
35 | - return !$this->running(); |
|
36 | - } |
|
37 | - |
|
38 | - public function setPID($pid) |
|
39 | - { |
|
40 | - $this->_pid = $pid; |
|
41 | - } |
|
42 | - |
|
43 | - public function getPID() |
|
44 | - { |
|
45 | - return $this->_pid; |
|
46 | - } |
|
8 | + protected $_pid; |
|
9 | + protected $_command; |
|
10 | + |
|
11 | + public function __construct($command = false) |
|
12 | + { |
|
13 | + if ($command) { |
|
14 | + $this->_command = $command; |
|
15 | + } |
|
16 | + } |
|
17 | + |
|
18 | + public function run() |
|
19 | + { |
|
20 | + $command = "nohup $this->_command > /dev/null 2>&1 & echo $!"; |
|
21 | + $this->_pid = shell_exec($command); |
|
22 | + |
|
23 | + return $this; |
|
24 | + } |
|
25 | + |
|
26 | + public function running() |
|
27 | + { |
|
28 | + exec("ps -p $this->_pid", $output); |
|
29 | + return isset($output[1]); |
|
30 | + } |
|
31 | + |
|
32 | + public function stop() |
|
33 | + { |
|
34 | + exec("kill $this->_pid"); |
|
35 | + return !$this->running(); |
|
36 | + } |
|
37 | + |
|
38 | + public function setPID($pid) |
|
39 | + { |
|
40 | + $this->_pid = $pid; |
|
41 | + } |
|
42 | + |
|
43 | + public function getPID() |
|
44 | + { |
|
45 | + return $this->_pid; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -3,24 +3,24 @@ |
||
3 | 3 | class Nip_Hash |
4 | 4 | { |
5 | 5 | |
6 | - protected static $golden_primes = array( |
|
7 | - 36 => array(1, 23, 809, 28837, 1038073, 37370257, 1345328833) |
|
8 | - ); |
|
6 | + protected static $golden_primes = array( |
|
7 | + 36 => array(1, 23, 809, 28837, 1038073, 37370257, 1345328833) |
|
8 | + ); |
|
9 | 9 | |
10 | - public static function uhash($num, $len = 5, $base = 36) |
|
11 | - { |
|
12 | - $gp = self::$golden_primes[$base]; |
|
13 | - $maxlen = count($gp); |
|
14 | - $len = $len > ($maxlen - 1) ? ($maxlen - 1) : $len; |
|
15 | - while ($len < $maxlen && pow($base, $len) < $num) |
|
16 | - $len++; |
|
17 | - if ($len >= $maxlen) |
|
18 | - throw new Exception($num . " out of range (max " . pow($base, $maxlen - 1) . ")"); |
|
19 | - $ceil = pow($base, $len); |
|
20 | - $prime = $gp[$len]; |
|
21 | - $dechash = ($num * $prime) % $ceil; |
|
22 | - $hash = base_convert($dechash, 10, $base); |
|
23 | - return str_pad($hash, $len, "0", STR_PAD_LEFT); |
|
24 | - } |
|
10 | + public static function uhash($num, $len = 5, $base = 36) |
|
11 | + { |
|
12 | + $gp = self::$golden_primes[$base]; |
|
13 | + $maxlen = count($gp); |
|
14 | + $len = $len > ($maxlen - 1) ? ($maxlen - 1) : $len; |
|
15 | + while ($len < $maxlen && pow($base, $len) < $num) |
|
16 | + $len++; |
|
17 | + if ($len >= $maxlen) |
|
18 | + throw new Exception($num . " out of range (max " . pow($base, $maxlen - 1) . ")"); |
|
19 | + $ceil = pow($base, $len); |
|
20 | + $prime = $gp[$len]; |
|
21 | + $dechash = ($num * $prime) % $ceil; |
|
22 | + $hash = base_convert($dechash, 10, $base); |
|
23 | + return str_pad($hash, $len, "0", STR_PAD_LEFT); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | } |
@@ -12,10 +12,12 @@ |
||
12 | 12 | $gp = self::$golden_primes[$base]; |
13 | 13 | $maxlen = count($gp); |
14 | 14 | $len = $len > ($maxlen - 1) ? ($maxlen - 1) : $len; |
15 | - while ($len < $maxlen && pow($base, $len) < $num) |
|
16 | - $len++; |
|
17 | - if ($len >= $maxlen) |
|
18 | - throw new Exception($num . " out of range (max " . pow($base, $maxlen - 1) . ")"); |
|
15 | + while ($len < $maxlen && pow($base, $len) < $num) { |
|
16 | + $len++; |
|
17 | + } |
|
18 | + if ($len >= $maxlen) { |
|
19 | + throw new Exception($num . " out of range (max " . pow($base, $maxlen - 1) . ")"); |
|
20 | + } |
|
19 | 21 | $ceil = pow($base, $len); |
20 | 22 | $prime = $gp[$len]; |
21 | 23 | $dechash = ($num * $prime) % $ceil; |
@@ -37,9 +37,9 @@ |
||
37 | 37 | $this->userAgent = $_SERVER['HTTP_USER_AGENT']; |
38 | 38 | $this->accept = $_SERVER['HTTP_ACCEPT']; |
39 | 39 | |
40 | - if (isset($_SERVER['HTTP_X_WAP_PROFILE'])|| isset($_SERVER['HTTP_PROFILE'])) { |
|
40 | + if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { |
|
41 | 41 | $this->isMobile = true; |
42 | - } elseif (strpos($this->accept,'text/vnd.wap.wml') > 0 || strpos($accept,'application/vnd.wap.xhtml+xml') > 0) { |
|
42 | + } elseif (strpos($this->accept, 'text/vnd.wap.wml') > 0 || strpos($accept, 'application/vnd.wap.xhtml+xml') > 0) { |
|
43 | 43 | $this->isMobile = true; |
44 | 44 | } else { |
45 | 45 | foreach ($this->devices as $device => $regexp) { |
@@ -15,67 +15,67 @@ |
||
15 | 15 | |
16 | 16 | class Nip_Flash { |
17 | 17 | |
18 | - protected $previous = array(); |
|
19 | - protected $next = array(); |
|
20 | - protected $session_var = 'flash-data'; |
|
18 | + protected $previous = array(); |
|
19 | + protected $next = array(); |
|
20 | + protected $session_var = 'flash-data'; |
|
21 | 21 | |
22 | 22 | |
23 | - public function __construct() { |
|
24 | - $this->read(); |
|
25 | - } |
|
23 | + public function __construct() { |
|
24 | + $this->read(); |
|
25 | + } |
|
26 | 26 | |
27 | - public function has($var) { |
|
28 | - return isset($this->previous[trim($var)]) ? true : false; |
|
29 | - } |
|
27 | + public function has($var) { |
|
28 | + return isset($this->previous[trim($var)]) ? true : false; |
|
29 | + } |
|
30 | 30 | |
31 | - public function get($var) { |
|
32 | - return isset($this->previous[trim($var)]) ? $this->previous[trim($var)] : null; |
|
33 | - } |
|
31 | + public function get($var) { |
|
32 | + return isset($this->previous[trim($var)]) ? $this->previous[trim($var)] : null; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - public function add($var, $value) { |
|
37 | - $this->next[trim($var)] = $value; |
|
38 | - $this->write(); |
|
39 | - } |
|
36 | + public function add($var, $value) { |
|
37 | + $this->next[trim($var)] = $value; |
|
38 | + $this->write(); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - public function remove($var) { |
|
43 | - unset($this->next[trim($var)]); |
|
44 | - $this->write(); |
|
45 | - } |
|
42 | + public function remove($var) { |
|
43 | + unset($this->next[trim($var)]); |
|
44 | + $this->write(); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - protected function clear() { |
|
49 | - $this->next = array(); |
|
50 | - } |
|
48 | + protected function clear() { |
|
49 | + $this->next = array(); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - public function read() { |
|
54 | - $data = $_SESSION[$this->session_var]; |
|
55 | - if (!is_null($data)) { |
|
56 | - if (is_array($data)) { |
|
57 | - $this->previous = $data; |
|
58 | - } |
|
59 | - unset($_SESSION[$this->session_var]); |
|
60 | - } |
|
61 | - } |
|
53 | + public function read() { |
|
54 | + $data = $_SESSION[$this->session_var]; |
|
55 | + if (!is_null($data)) { |
|
56 | + if (is_array($data)) { |
|
57 | + $this->previous = $data; |
|
58 | + } |
|
59 | + unset($_SESSION[$this->session_var]); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - protected function write() { |
|
65 | - $_SESSION[$this->session_var] = $this->next; |
|
66 | - } |
|
64 | + protected function write() { |
|
65 | + $_SESSION[$this->session_var] = $this->next; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Returns static instance |
|
71 | - * |
|
72 | - * @return Nip_Flash |
|
73 | - */ |
|
74 | - static public function &instance() { |
|
75 | - static $instance; |
|
76 | - if (!($instance instanceof self)) { |
|
77 | - $instance = new self(); |
|
78 | - } |
|
79 | - return $instance; |
|
80 | - } |
|
69 | + /** |
|
70 | + * Returns static instance |
|
71 | + * |
|
72 | + * @return Nip_Flash |
|
73 | + */ |
|
74 | + static public function &instance() { |
|
75 | + static $instance; |
|
76 | + if (!($instance instanceof self)) { |
|
77 | + $instance = new self(); |
|
78 | + } |
|
79 | + return $instance; |
|
80 | + } |
|
81 | 81 | } |
82 | 82 | \ No newline at end of file |
@@ -15,9 +15,9 @@ |
||
15 | 15 | |
16 | 16 | class Nip_Flash { |
17 | 17 | |
18 | - protected $previous = array(); |
|
19 | - protected $next = array(); |
|
20 | - protected $session_var = 'flash-data'; |
|
18 | + protected $previous = array(); |
|
19 | + protected $next = array(); |
|
20 | + protected $session_var = 'flash-data'; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | public function __construct() { |