@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | { |
113 | 113 | $number = (int) $args[1]; |
114 | 114 | $key = self::_getPluralForm($number); |
115 | - $max = count(self::$_translations[$messageId]) - 1; |
|
115 | + $max = count(self::$_translations[$messageId])-1; |
|
116 | 116 | if ($key > $max) $key = $max; |
117 | 117 | |
118 | 118 | $args[0] = self::$_translations[$messageId][$key]; |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | protected static function _matchLanguage($a, $b) { |
387 | 387 | $a = explode('-', $a); |
388 | 388 | $b = explode('-', $b); |
389 | - for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i) |
|
389 | + for ($i = 0, $n = min(count($a), count($b)); $i < $n; ++$i) |
|
390 | 390 | { |
391 | 391 | if ($a[$i] !== $b[$i]) break; |
392 | 392 | } |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | if (strlen($filename)) |
53 | 53 | { |
54 | 54 | return self::$_path . DIRECTORY_SEPARATOR . $filename; |
55 | - } |
|
56 | - else |
|
55 | + } else |
|
57 | 56 | { |
58 | 57 | return self::$_path; |
59 | 58 | } |
@@ -84,9 +83,10 @@ discard block |
||
84 | 83 | protected static function _initialize() |
85 | 84 | { |
86 | 85 | // Create storage directory if it does not exist. |
87 | - if (!is_dir(self::$_path)) |
|
88 | - if (!@mkdir(self::$_path)) |
|
86 | + if (!is_dir(self::$_path)) { |
|
87 | + if (!@mkdir(self::$_path)) |
|
89 | 88 | throw new Exception('unable to create directory ' . self::$_path, 10); |
89 | + } |
|
90 | 90 | |
91 | 91 | // Create .htaccess file if it does not exist. |
92 | 92 | $file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess'; |
@@ -40,7 +40,9 @@ discard block |
||
40 | 40 | if ( |
41 | 41 | is_array($options) && |
42 | 42 | array_key_exists('dir', $options) |
43 | - ) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR; |
|
43 | + ) { |
|
44 | + self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR; |
|
45 | + } |
|
44 | 46 | // if needed initialize the singleton |
45 | 47 | if (!(self::$_instance instanceof privatebin_data)) { |
46 | 48 | self::$_instance = new self; |
@@ -60,8 +62,12 @@ discard block |
||
60 | 62 | public function create($pasteid, $paste) |
61 | 63 | { |
62 | 64 | $storagedir = self::_dataid2path($pasteid); |
63 | - if (is_file($storagedir . $pasteid)) return false; |
|
64 | - if (!is_dir($storagedir)) mkdir($storagedir, 0705, true); |
|
65 | + if (is_file($storagedir . $pasteid)) { |
|
66 | + return false; |
|
67 | + } |
|
68 | + if (!is_dir($storagedir)) { |
|
69 | + mkdir($storagedir, 0705, true); |
|
70 | + } |
|
65 | 71 | return (bool) @file_put_contents($storagedir . $pasteid, json_encode($paste)); |
66 | 72 | } |
67 | 73 | |
@@ -74,7 +80,9 @@ discard block |
||
74 | 80 | */ |
75 | 81 | public function read($pasteid) |
76 | 82 | { |
77 | - if (!$this->exists($pasteid)) return false; |
|
83 | + if (!$this->exists($pasteid)) { |
|
84 | + return false; |
|
85 | + } |
|
78 | 86 | $paste = json_decode( |
79 | 87 | file_get_contents(self::_dataid2path($pasteid) . $pasteid) |
80 | 88 | ); |
@@ -111,7 +119,9 @@ discard block |
||
111 | 119 | $dir = dir($discdir); |
112 | 120 | while (false !== ($filename = $dir->read())) |
113 | 121 | { |
114 | - if (is_file($discdir . $filename)) @unlink($discdir . $filename); |
|
122 | + if (is_file($discdir . $filename)) { |
|
123 | + @unlink($discdir . $filename); |
|
124 | + } |
|
115 | 125 | } |
116 | 126 | $dir->close(); |
117 | 127 | |
@@ -146,8 +156,12 @@ discard block |
||
146 | 156 | { |
147 | 157 | $storagedir = self::_dataid2discussionpath($pasteid); |
148 | 158 | $filename = $pasteid . '.' . $commentid . '.' . $parentid; |
149 | - if (is_file($storagedir . $filename)) return false; |
|
150 | - if (!is_dir($storagedir)) mkdir($storagedir, 0705, true); |
|
159 | + if (is_file($storagedir . $filename)) { |
|
160 | + return false; |
|
161 | + } |
|
162 | + if (!is_dir($storagedir)) { |
|
163 | + mkdir($storagedir, 0705, true); |
|
164 | + } |
|
151 | 165 | return (bool) @file_put_contents($storagedir . $filename, json_encode($comment)); |
152 | 166 | } |
153 | 167 | |
@@ -245,15 +259,21 @@ discard block |
||
245 | 259 | $secondKey = array_rand($secondLevel); |
246 | 260 | $path = self::$_dir . $firstLevel[$firstKey] . |
247 | 261 | DIRECTORY_SEPARATOR . $secondLevel[$secondKey]; |
248 | - if (!is_dir($path)) continue; |
|
262 | + if (!is_dir($path)) { |
|
263 | + continue; |
|
264 | + } |
|
249 | 265 | $thirdLevel = array_filter( |
250 | 266 | scandir($path), |
251 | 267 | array('model_paste', 'isValidId') |
252 | 268 | ); |
253 | - if (count($thirdLevel) == 0) continue; |
|
269 | + if (count($thirdLevel) == 0) { |
|
270 | + continue; |
|
271 | + } |
|
254 | 272 | $thirdKey = array_rand($thirdLevel); |
255 | 273 | $pasteid = $thirdLevel[$thirdKey]; |
256 | - if (in_array($pasteid, $pastes)) continue; |
|
274 | + if (in_array($pasteid, $pastes)) { |
|
275 | + continue; |
|
276 | + } |
|
257 | 277 | |
258 | 278 | if ($this->exists($pasteid)) |
259 | 279 | { |
@@ -264,7 +284,9 @@ discard block |
||
264 | 284 | ) |
265 | 285 | { |
266 | 286 | $pastes[] = $pasteid; |
267 | - if (count($pastes) >= $batchsize) break; |
|
287 | + if (count($pastes) >= $batchsize) { |
|
288 | + break; |
|
289 | + } |
|
268 | 290 | } |
269 | 291 | } |
270 | 292 | } |
@@ -282,7 +304,9 @@ discard block |
||
282 | 304 | private static function _init() |
283 | 305 | { |
284 | 306 | // Create storage directory if it does not exist. |
285 | - if (!is_dir(self::$_dir)) mkdir(self::$_dir, 0705); |
|
307 | + if (!is_dir(self::$_dir)) { |
|
308 | + mkdir(self::$_dir, 0705); |
|
309 | + } |
|
286 | 310 | // Create .htaccess file if it does not exist. |
287 | 311 | if (!is_file(self::$_dir . '.htaccess')) |
288 | 312 | { |
@@ -117,13 +117,13 @@ |
||
117 | 117 | // purge file of expired IPs to keep it small |
118 | 118 | foreach ($tl as $key => $time) |
119 | 119 | { |
120 | - if ($time + self::$_limit < $now) |
|
120 | + if ($time+self::$_limit < $now) |
|
121 | 121 | { |
122 | 122 | unset($tl[$key]); |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - if (array_key_exists($ip, $tl) && ($tl[$ip] + self::$_limit >= $now)) |
|
126 | + if (array_key_exists($ip, $tl) && ($tl[$ip]+self::$_limit >= $now)) |
|
127 | 127 | { |
128 | 128 | $result = false; |
129 | 129 | } else { |