@@ -9,7 +9,9 @@ |
||
9 | 9 | { |
10 | 10 | /* Setup Routine */ |
11 | 11 | $this->_path = PATH . 'data'; |
12 | - if(!is_dir($this->_path)) mkdir($this->_path); |
|
12 | + if(!is_dir($this->_path)) { |
|
13 | + mkdir($this->_path); |
|
14 | + } |
|
13 | 15 | $this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png'; |
14 | 16 | serversalt::setPath($this->_path); |
15 | 17 | } |
@@ -2,10 +2,18 @@ discard block |
||
2 | 2 | error_reporting( E_ALL | E_STRICT ); |
3 | 3 | |
4 | 4 | // change this, if your php files and data is outside of your webservers document root |
5 | -if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..'); |
|
6 | -if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR); |
|
7 | -if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'); |
|
8 | -if (!is_file(CONF)) copy(CONF . '.sample', CONF); |
|
5 | +if (!defined('PUBLIC_PATH')) { |
|
6 | + define('PUBLIC_PATH', '..'); |
|
7 | +} |
|
8 | +if (!defined('PATH')) { |
|
9 | + define('PATH', '..' . DIRECTORY_SEPARATOR); |
|
10 | +} |
|
11 | +if (!defined('CONF')) { |
|
12 | + define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'); |
|
13 | +} |
|
14 | +if (!is_file(CONF)) { |
|
15 | + copy(CONF . '.sample', CONF); |
|
16 | +} |
|
9 | 17 | |
10 | 18 | require PATH . 'lib/auto.php'; |
11 | 19 | |
@@ -100,8 +108,9 @@ discard block |
||
100 | 108 | $example = self::getPaste(); |
101 | 109 | // the JSON shouldn't contain the salt |
102 | 110 | unset($example['meta']['salt']); |
103 | - if (count($meta)) |
|
104 | - $example['meta'] = $meta; |
|
111 | + if (count($meta)) { |
|
112 | + $example['meta'] = $meta; |
|
113 | + } |
|
105 | 114 | $example['comments'] = array(); |
106 | 115 | $example['comment_count'] = 0; |
107 | 116 | $example['comment_offset'] = 0; |
@@ -178,8 +187,9 @@ discard block |
||
178 | 187 | */ |
179 | 188 | public static function confBackup() |
180 | 189 | { |
181 | - if (!is_file(CONF . '.bak') && is_file(CONF)) |
|
182 | - rename(CONF, CONF . '.bak'); |
|
190 | + if (!is_file(CONF . '.bak') && is_file(CONF)) { |
|
191 | + rename(CONF, CONF . '.bak'); |
|
192 | + } |
|
183 | 193 | } |
184 | 194 | |
185 | 195 | /** |
@@ -189,8 +199,9 @@ discard block |
||
189 | 199 | */ |
190 | 200 | public static function confRestore() |
191 | 201 | { |
192 | - if (is_file(CONF . '.bak')) |
|
193 | - rename(CONF . '.bak', CONF); |
|
202 | + if (is_file(CONF . '.bak')) { |
|
203 | + rename(CONF . '.bak', CONF); |
|
204 | + } |
|
194 | 205 | } |
195 | 206 | |
196 | 207 | /** |
@@ -13,13 +13,17 @@ discard block |
||
13 | 13 | { |
14 | 14 | /* Setup Routine */ |
15 | 15 | $this->_path = PATH . 'data'; |
16 | - if(!is_dir($this->_path)) mkdir($this->_path); |
|
16 | + if(!is_dir($this->_path)) { |
|
17 | + mkdir($this->_path); |
|
18 | + } |
|
17 | 19 | serversalt::setPath($this->_path); |
18 | 20 | |
19 | 21 | $this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo'; |
20 | 22 | |
21 | 23 | $this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar'; |
22 | - if(!is_dir($this->_invalidPath)) mkdir($this->_invalidPath); |
|
24 | + if(!is_dir($this->_invalidPath)) { |
|
25 | + mkdir($this->_invalidPath); |
|
26 | + } |
|
23 | 27 | $this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php'; |
24 | 28 | } |
25 | 29 | |
@@ -39,7 +43,9 @@ discard block |
||
39 | 43 | // mcrypt mock |
40 | 44 | if (!function_exists('mcrypt_create_iv')) |
41 | 45 | { |
42 | - if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1); |
|
46 | + if (!defined('MCRYPT_DEV_URANDOM')) { |
|
47 | + define('MCRYPT_DEV_URANDOM', 1); |
|
48 | + } |
|
43 | 49 | function mcrypt_create_iv($int, $flag) |
44 | 50 | { |
45 | 51 | $randomSalt = ''; |
@@ -22,8 +22,9 @@ |
||
22 | 22 | $_POST = array(); |
23 | 23 | $_GET = array(); |
24 | 24 | $_SERVER = array(); |
25 | - if ($this->_model->exists(helper::getPasteId())) |
|
26 | - $this->_model->delete(helper::getPasteId()); |
|
25 | + if ($this->_model->exists(helper::getPasteId())) { |
|
26 | + $this->_model->delete(helper::getPasteId()); |
|
27 | + } |
|
27 | 28 | helper::confRestore(); |
28 | 29 | } |
29 | 30 |
@@ -95,7 +95,9 @@ |
||
95 | 95 | public static function canPass() |
96 | 96 | { |
97 | 97 | // disable limits if set to less then 1 |
98 | - if (self::$_limit < 1) return true; |
|
98 | + if (self::$_limit < 1) { |
|
99 | + return true; |
|
100 | + } |
|
99 | 101 | |
100 | 102 | $ip = hash_hmac('sha256', self::getIp(), serversalt::get()); |
101 | 103 |
@@ -86,7 +86,9 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function generate($text) |
88 | 88 | { |
89 | - if (!function_exists('gd_info')) return ''; |
|
89 | + if (!function_exists('gd_info')) { |
|
90 | + return ''; |
|
91 | + } |
|
90 | 92 | |
91 | 93 | // We hash the input string. |
92 | 94 | $hash=hash('sha1',$text.$this->salt).hash('md5',$text.$this->salt); |
@@ -181,8 +183,7 @@ discard block |
||
181 | 183 | */ |
182 | 184 | private function degrade($img,$direction,$color1,$color2) |
183 | 185 | { |
184 | - if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); } |
|
185 | - else { $size = imagesy($img); $sizeinv = imagesx($img);} |
|
186 | + if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); } else { $size = imagesy($img); $sizeinv = imagesx($img);} |
|
186 | 187 | $diffs = array( |
187 | 188 | (($color2[0]-$color1[0])/$size), |
188 | 189 | (($color2[1]-$color1[1])/$size), |
@@ -193,8 +194,7 @@ discard block |
||
193 | 194 | $r = $color1[0]+($diffs[0]*$i); |
194 | 195 | $g = $color1[1]+($diffs[1]*$i); |
195 | 196 | $b = $color1[2]+($diffs[2]*$i); |
196 | - if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); } |
|
197 | - else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); } |
|
197 | + if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); } else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); } |
|
198 | 198 | } |
199 | 199 | return $img; |
200 | 200 | } |
@@ -27,7 +27,9 @@ discard block |
||
27 | 27 | public function get() |
28 | 28 | { |
29 | 29 | $this->_data = $this->_store->read($this->getId()); |
30 | - if ($this->_data === false) throw new Exception(zerobin::GENERIC_ERROR, 64); |
|
30 | + if ($this->_data === false) { |
|
31 | + throw new Exception(zerobin::GENERIC_ERROR, 64); |
|
32 | + } |
|
31 | 33 | |
32 | 34 | // check if paste has expired and delete it if neccessary. |
33 | 35 | if (property_exists($this->_data->meta, 'expire_date')) |
@@ -48,8 +50,7 @@ discard block |
||
48 | 50 | if (property_exists($this->_data->meta, 'syntaxcoloring') && $this->_data->meta->syntaxcoloring === true) |
49 | 51 | { |
50 | 52 | $this->_data->meta->formatter = 'syntaxhighlighting'; |
51 | - } |
|
52 | - else |
|
53 | + } else |
|
53 | 54 | { |
54 | 55 | $this->_data->meta->formatter = $this->_conf->getKey('defaultformatter'); |
55 | 56 | } |
@@ -77,8 +78,9 @@ discard block |
||
77 | 78 | public function store() |
78 | 79 | { |
79 | 80 | // Check for improbable collision. |
80 | - if ($this->exists()) |
|
81 | - throw new Exception('You are unlucky. Try again.', 75); |
|
81 | + if ($this->exists()) { |
|
82 | + throw new Exception('You are unlucky. Try again.', 75); |
|
83 | + } |
|
82 | 84 | |
83 | 85 | $this->_data->meta->postdate = time(); |
84 | 86 | $this->_data->meta->salt = serversalt::generate(); |
@@ -89,7 +91,9 @@ discard block |
||
89 | 91 | $this->getId(), |
90 | 92 | json_decode(json_encode($this->_data), true) |
91 | 93 | ) === false |
92 | - ) throw new Exception('Error saving paste. Sorry.', 76); |
|
94 | + ) { |
|
95 | + throw new Exception('Error saving paste. Sorry.', 76); |
|
96 | + } |
|
93 | 97 | } |
94 | 98 | |
95 | 99 | /** |
@@ -133,7 +137,9 @@ discard block |
||
133 | 137 | $comment = new model_comment($this->_conf, $this->_store); |
134 | 138 | $comment->setPaste($this); |
135 | 139 | $comment->setParentId($parentId); |
136 | - if ($commentId !== null) $comment->setId($commentId); |
|
140 | + if ($commentId !== null) { |
|
141 | + $comment->setId($commentId); |
|
142 | + } |
|
137 | 143 | return $comment; |
138 | 144 | } |
139 | 145 | |
@@ -160,7 +166,9 @@ discard block |
||
160 | 166 | */ |
161 | 167 | public function getDeleteToken() |
162 | 168 | { |
163 | - if (!property_exists($this->_data->meta, 'salt')) $this->get(); |
|
169 | + if (!property_exists($this->_data->meta, 'salt')) { |
|
170 | + $this->get(); |
|
171 | + } |
|
164 | 172 | return hash_hmac( |
165 | 173 | $this->_conf->getKey('zerobincompatibility') ? 'sha1' : 'sha256', |
166 | 174 | $this->getId(), |
@@ -178,8 +186,9 @@ discard block |
||
178 | 186 | */ |
179 | 187 | public function setAttachment($attachment) |
180 | 188 | { |
181 | - if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachment)) |
|
182 | - throw new Exception('Invalid attachment.', 71); |
|
189 | + if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachment)) { |
|
190 | + throw new Exception('Invalid attachment.', 71); |
|
191 | + } |
|
183 | 192 | $this->_data->meta->attachment = $attachment; |
184 | 193 | } |
185 | 194 | |
@@ -193,8 +202,9 @@ discard block |
||
193 | 202 | */ |
194 | 203 | public function setAttachmentName($attachmentname) |
195 | 204 | { |
196 | - if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachmentname)) |
|
197 | - throw new Exception('Invalid attachment.', 72); |
|
205 | + if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachmentname)) { |
|
206 | + throw new Exception('Invalid attachment.', 72); |
|
207 | + } |
|
198 | 208 | $this->_data->meta->attachmentname = $attachmentname; |
199 | 209 | } |
200 | 210 | |
@@ -211,13 +221,14 @@ discard block |
||
211 | 221 | if (array_key_exists($expiration, $expire_options)) |
212 | 222 | { |
213 | 223 | $expire = $expire_options[$expiration]; |
214 | - } |
|
215 | - else |
|
224 | + } else |
|
216 | 225 | { |
217 | 226 | // using getKey() to ensure a default value is present |
218 | 227 | $expire = $this->_conf->getKey($this->_conf->getKey('default', 'expire'), 'expire_options'); |
219 | 228 | } |
220 | - if ($expire > 0) $this->_data->meta->expire_date = time() + $expire; |
|
229 | + if ($expire > 0) { |
|
230 | + $this->_data->meta->expire_date = time() + $expire; |
|
231 | + } |
|
221 | 232 | } |
222 | 233 | |
223 | 234 | /** |
@@ -233,11 +244,11 @@ discard block |
||
233 | 244 | if ($burnafterreading === '0') |
234 | 245 | { |
235 | 246 | $this->_data->meta->burnafterreading = false; |
236 | - } |
|
237 | - else |
|
247 | + } else |
|
238 | 248 | { |
239 | - if ($burnafterreading !== '1') |
|
240 | - throw new Exception('Invalid data.', 73); |
|
249 | + if ($burnafterreading !== '1') { |
|
250 | + throw new Exception('Invalid data.', 73); |
|
251 | + } |
|
241 | 252 | $this->_data->meta->burnafterreading = true; |
242 | 253 | $this->_data->meta->opendiscussion = false; |
243 | 254 | } |
@@ -260,11 +271,11 @@ discard block |
||
260 | 271 | ) |
261 | 272 | { |
262 | 273 | $this->_data->meta->opendiscussion = false; |
263 | - } |
|
264 | - else |
|
274 | + } else |
|
265 | 275 | { |
266 | - if ($opendiscussion !== '1') |
|
267 | - throw new Exception('Invalid data.', 74); |
|
276 | + if ($opendiscussion !== '1') { |
|
277 | + throw new Exception('Invalid data.', 74); |
|
278 | + } |
|
268 | 279 | $this->_data->meta->opendiscussion = true; |
269 | 280 | } |
270 | 281 | } |
@@ -295,7 +306,9 @@ discard block |
||
295 | 306 | */ |
296 | 307 | public function isBurnafterreading() |
297 | 308 | { |
298 | - if (!property_exists($this->_data, 'data')) $this->get(); |
|
309 | + if (!property_exists($this->_data, 'data')) { |
|
310 | + $this->get(); |
|
311 | + } |
|
299 | 312 | return property_exists($this->_data->meta, 'burnafterreading') && |
300 | 313 | $this->_data->meta->burnafterreading === true; |
301 | 314 | } |
@@ -310,7 +323,9 @@ discard block |
||
310 | 323 | */ |
311 | 324 | public function isOpendiscussion() |
312 | 325 | { |
313 | - if (!property_exists($this->_data, 'data')) $this->get(); |
|
326 | + if (!property_exists($this->_data, 'data')) { |
|
327 | + $this->get(); |
|
328 | + } |
|
314 | 329 | return property_exists($this->_data->meta, 'opendiscussion') && |
315 | 330 | $this->_data->meta->opendiscussion === true; |
316 | 331 | } |
@@ -86,7 +86,9 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setId($id) |
88 | 88 | { |
89 | - if (!self::isValidId($id)) throw new Exception('Invalid paste ID.', 60); |
|
89 | + if (!self::isValidId($id)) { |
|
90 | + throw new Exception('Invalid paste ID.', 60); |
|
91 | + } |
|
90 | 92 | $this->_id = $id; |
91 | 93 | } |
92 | 94 | |
@@ -100,7 +102,9 @@ discard block |
||
100 | 102 | */ |
101 | 103 | public function setData($data) |
102 | 104 | { |
103 | - if (!sjcl::isValid($data)) throw new Exception('Invalid data.', 61); |
|
105 | + if (!sjcl::isValid($data)) { |
|
106 | + throw new Exception('Invalid data.', 61); |
|
107 | + } |
|
104 | 108 | $this->_data->data = $data; |
105 | 109 | |
106 | 110 | // We just want a small hash to avoid collisions: |
@@ -59,16 +59,19 @@ discard block |
||
59 | 59 | { |
60 | 60 | // Make sure paste exists. |
61 | 61 | $pasteid = $this->getPaste()->getId(); |
62 | - if (!$this->getPaste()->exists()) |
|
63 | - throw new Exception('Invalid data.', 67); |
|
62 | + if (!$this->getPaste()->exists()) { |
|
63 | + throw new Exception('Invalid data.', 67); |
|
64 | + } |
|
64 | 65 | |
65 | 66 | // Make sure the discussion is opened in this paste and in configuration. |
66 | - if (!$this->getPaste()->isOpendiscussion() || !$this->_conf->getKey('discussion')) |
|
67 | - throw new Exception('Invalid data.', 68); |
|
67 | + if (!$this->getPaste()->isOpendiscussion() || !$this->_conf->getKey('discussion')) { |
|
68 | + throw new Exception('Invalid data.', 68); |
|
69 | + } |
|
68 | 70 | |
69 | 71 | // Check for improbable collision. |
70 | - if ($this->exists()) |
|
71 | - throw new Exception('You are unlucky. Try again.', 69); |
|
72 | + if ($this->exists()) { |
|
73 | + throw new Exception('You are unlucky. Try again.', 69); |
|
74 | + } |
|
72 | 75 | |
73 | 76 | $this->_data->meta->postdate = time(); |
74 | 77 | |
@@ -80,7 +83,9 @@ discard block |
||
80 | 83 | $this->getId(), |
81 | 84 | json_decode(json_encode($this->_data), true) |
82 | 85 | ) === false |
83 | - ) throw new Exception('Error saving comment. Sorry.', 70); |
|
86 | + ) { |
|
87 | + throw new Exception('Error saving comment. Sorry.', 70); |
|
88 | + } |
|
84 | 89 | } |
85 | 90 | |
86 | 91 | /** |
@@ -145,7 +150,9 @@ discard block |
||
145 | 150 | */ |
146 | 151 | public function setParentId($id) |
147 | 152 | { |
148 | - if (!self::isValidId($id)) throw new Exception('Invalid paste ID.', 65); |
|
153 | + if (!self::isValidId($id)) { |
|
154 | + throw new Exception('Invalid paste ID.', 65); |
|
155 | + } |
|
149 | 156 | $this->_data->meta->parentid = $id; |
150 | 157 | } |
151 | 158 | |
@@ -157,7 +164,9 @@ discard block |
||
157 | 164 | */ |
158 | 165 | public function getParentId() |
159 | 166 | { |
160 | - if (!property_exists($this->_data->meta, 'parentid')) $this->_data->meta->parentid = ''; |
|
167 | + if (!property_exists($this->_data->meta, 'parentid')) { |
|
168 | + $this->_data->meta->parentid = ''; |
|
169 | + } |
|
161 | 170 | return $this->_data->meta->parentid; |
162 | 171 | } |
163 | 172 | |
@@ -171,7 +180,9 @@ discard block |
||
171 | 180 | */ |
172 | 181 | public function setNickname($nickname) |
173 | 182 | { |
174 | - if (!sjcl::isValid($nickname)) throw new Exception('Invalid data.', 66); |
|
183 | + if (!sjcl::isValid($nickname)) { |
|
184 | + throw new Exception('Invalid data.', 66); |
|
185 | + } |
|
175 | 186 | $this->_data->meta->nickname = $nickname; |
176 | 187 | |
177 | 188 | // Generation of the anonymous avatar (Vizhash): |