@@ -154,7 +154,7 @@ |
||
| 154 | 154 | $overallbitrate = $track['Overall_bit_rate']; |
| 155 | 155 | } |
| 156 | 156 | if (isset($track['Unique_ID'])) { |
| 157 | - if(preg_match('/\(0x(?P<hash>[0-9a-f]{32})\)/i', $track['Unique_ID'], $matches)){ |
|
| 157 | + if(preg_match('/\(0x(?P<hash>[0-9a-f]{32})\)/i', $track['Unique_ID'], $matches)) { |
|
| 158 | 158 | $uniqueid = $matches['hash']; |
| 159 | 159 | $this->addUID($releaseID, $uniqueid); |
| 160 | 160 | } |
@@ -197,8 +197,7 @@ |
||
| 197 | 197 | !preg_match('/\.(apk|bat|bmp|cbr|cbz|cfg|css|csv|cue|db|dll|doc|epub|exe|gif|htm|ico|idx|ini' . |
| 198 | 198 | '|jpg|lit|log|m3u|mid|mobi|mp3|nib|nzb|odt|opf|otf|par|par2|pdf|psd|pps|png|ppt|r\d{2,4}' . |
| 199 | 199 | '|rar|sfv|srr|sub|srt|sql|rom|rtf|tif|torrent|ttf|txt|vb|vol\d+\+\d+|wps|xml|zip)/i', |
| 200 | - $subject)) |
|
| 201 | - { |
|
| 200 | + $subject)) { |
|
| 202 | 201 | $hiddenID = (string)$nzbcontents->segments->segment; |
| 203 | 202 | $hiddenNFO = true; |
| 204 | 203 | } |
@@ -3,7 +3,8 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | use ReCaptcha\ReCaptcha; |
| 5 | 5 | |
| 6 | -class Captcha { |
|
| 6 | +class Captcha |
|
| 7 | +{ |
|
| 7 | 8 | /** |
| 8 | 9 | * Smarty $page |
| 9 | 10 | * |
@@ -69,7 +70,8 @@ discard block |
||
| 69 | 70 | * @note Passing $page by reference to setup smarty vars easily. |
| 70 | 71 | * @param \Page $page |
| 71 | 72 | */ |
| 72 | - public function __construct(&$page) { |
|
| 73 | + public function __construct(&$page) |
|
| 74 | + { |
|
| 73 | 75 | if (!$page instanceof \Page) { |
| 74 | 76 | throw new \InvalidArgumentException('Invalid Page variable provided'); |
| 75 | 77 | } |
@@ -99,7 +101,8 @@ discard block |
||
| 99 | 101 | * |
| 100 | 102 | * @return bool |
| 101 | 103 | */ |
| 102 | - public function shouldDisplay() { |
|
| 104 | + public function shouldDisplay() |
|
| 105 | + { |
|
| 103 | 106 | if ($this->_bootstrapCaptcha()) { |
| 104 | 107 | return true; |
| 105 | 108 | } |
@@ -112,7 +115,8 @@ discard block |
||
| 112 | 115 | * |
| 113 | 116 | * @return string |
| 114 | 117 | */ |
| 115 | - public function getError() { |
|
| 118 | + public function getError() |
|
| 119 | + { |
|
| 116 | 120 | return $this->error; |
| 117 | 121 | } |
| 118 | 122 | |
@@ -123,7 +127,8 @@ discard block |
||
| 123 | 127 | * @param string $ip |
| 124 | 128 | * @return bool |
| 125 | 129 | */ |
| 126 | - public function processCaptcha($response, $ip) { |
|
| 130 | + public function processCaptcha($response, $ip) |
|
| 131 | + { |
|
| 127 | 132 | if (isset($response[self::RECAPTCHA_POSTKEY])) { |
| 128 | 133 | $post_response = $response[self::RECAPTCHA_POSTKEY]; |
| 129 | 134 | } else { |
@@ -146,7 +151,8 @@ discard block |
||
| 146 | 151 | * |
| 147 | 152 | * @param array $codes |
| 148 | 153 | */ |
| 149 | - private function _handleErrors($codes) { |
|
| 154 | + private function _handleErrors($codes) |
|
| 155 | + { |
|
| 150 | 156 | $rc_error = 'ReCaptcha Failed: '; |
| 151 | 157 | |
| 152 | 158 | foreach ($codes as $c) { |
@@ -177,7 +183,8 @@ discard block |
||
| 177 | 183 | * |
| 178 | 184 | * @return bool |
| 179 | 185 | */ |
| 180 | - private function _bootstrapCaptcha() { |
|
| 186 | + private function _bootstrapCaptcha() |
|
| 187 | + { |
|
| 181 | 188 | if ($this->recaptcha instanceof ReCaptcha) { |
| 182 | 189 | return true; |
| 183 | 190 | } |
@@ -130,7 +130,8 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @access public |
| 132 | 132 | */ |
| 133 | - public function isNFO(&$possibleNFO, $guid) { |
|
| 133 | + public function isNFO(&$possibleNFO, $guid) |
|
| 134 | + { |
|
| 134 | 135 | if ($possibleNFO === false) { |
| 135 | 136 | return false; |
| 136 | 137 | } |
@@ -141,8 +142,7 @@ discard block |
||
| 141 | 142 | $size > 11 && |
| 142 | 143 | !preg_match( |
| 143 | 144 | '/\A(\s*<\?xml|=newz\[NZB\]=|RIFF|\s*[RP]AR|.{0,10}(JFIF|matroska|ftyp|ID3))|;\s*Generated\s*by.*SF\w/i' |
| 144 | - , $possibleNFO)) |
|
| 145 | - { |
|
| 145 | + , $possibleNFO)) { |
|
| 146 | 146 | // File/GetId3 work with files, so save to disk. |
| 147 | 147 | $tmpPath = $this->tmpPath . $guid . '.nfo'; |
| 148 | 148 | file_put_contents($tmpPath, $possibleNFO); |
@@ -158,8 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | // Or binary. |
| 160 | 160 | } else if (preg_match('/^(JPE?G|Parity|PNG|RAR|XML|(7-)?[Zz]ip)/', $result) || |
| 161 | - preg_match('/[\x00-\x08\x12-\x1F\x0B\x0E\x0F]/', $possibleNFO)) |
|
| 162 | - { |
|
| 161 | + preg_match('/[\x00-\x08\x12-\x1F\x0B\x0E\x0F]/', $possibleNFO)) { |
|
| 163 | 162 | @unlink($tmpPath); |
| 164 | 163 | return false; |
| 165 | 164 | } |
@@ -17,13 +17,24 @@ discard block |
||
| 17 | 17 | define('OPENSSL_CFG_PATH', NN_LIB . '/config/openssl.cnf'); |
| 18 | 18 | |
| 19 | 19 | // JSON Encode Support (for those missing the constants) |
| 20 | -if(!defined('JSON_HEX_TAG')) define('JSON_HEX_TAG', 1); |
|
| 21 | -if(!defined('JSON_HEX_AMP')) define('JSON_HEX_AMP', 2); |
|
| 22 | -if(!defined('JSON_HEX_APOS')) define('JSON_HEX_APOS', 4); |
|
| 23 | -if(!defined('JSON_HEX_QUOT')) define('JSON_HEX_QUOT', 8); |
|
| 24 | -if(!defined('JSON_UNESCAPED_UNICODE')) define('JSON_UNESCAPED_UNICODE', 256); |
|
| 20 | +if(!defined('JSON_HEX_TAG')) { |
|
| 21 | + define('JSON_HEX_TAG', 1); |
|
| 22 | +} |
|
| 23 | +if(!defined('JSON_HEX_AMP')) { |
|
| 24 | + define('JSON_HEX_AMP', 2); |
|
| 25 | +} |
|
| 26 | +if(!defined('JSON_HEX_APOS')) { |
|
| 27 | + define('JSON_HEX_APOS', 4); |
|
| 28 | +} |
|
| 29 | +if(!defined('JSON_HEX_QUOT')) { |
|
| 30 | + define('JSON_HEX_QUOT', 8); |
|
| 31 | +} |
|
| 32 | +if(!defined('JSON_UNESCAPED_UNICODE')) { |
|
| 33 | + define('JSON_UNESCAPED_UNICODE', 256); |
|
| 34 | +} |
|
| 25 | 35 | |
| 26 | -class SpotNab { |
|
| 36 | +class SpotNab |
|
| 37 | +{ |
|
| 27 | 38 | // Segment Identifier domain is used to help build segments |
| 28 | 39 | // prior to them being posted. |
| 29 | 40 | const SEGID_DOMAIN = 'sample.com'; |
@@ -134,7 +145,8 @@ discard block |
||
| 134 | 145 | /* Track the last article scanned when preforming a discovery */ |
| 135 | 146 | private $_discovery_lastarticle; |
| 136 | 147 | |
| 137 | - public function __construct($post_user = NULL, $post_email = NULL, $post_group = NULL) { |
|
| 148 | + public function __construct($post_user = NULL, $post_email = NULL, $post_group = NULL) |
|
| 149 | + { |
|
| 138 | 150 | $this->_pdo = new Settings(); |
| 139 | 151 | $this->_nntp = new NNTP(['Settings' => $this->_pdo]); |
| 140 | 152 | $this->releaseImage = new ReleaseImage($this->_pdo); |
@@ -151,19 +163,19 @@ discard block |
||
| 151 | 163 | $this->_post_title = trim($this->_pdo->getSetting('title'))? |
| 152 | 164 | $this->_pdo->getSetting('title'):NULL; |
| 153 | 165 | |
| 154 | - if ($this->_post_user === NULL){ |
|
| 166 | + if ($this->_post_user === NULL) { |
|
| 155 | 167 | // Fetch the SpotNab UserID |
| 156 | 168 | $this->_post_user = trim($this->_pdo->getSetting('spotnabuser'))? |
| 157 | 169 | $this->_pdo->getSetting('spotnabuser'):NULL; |
| 158 | 170 | } |
| 159 | 171 | |
| 160 | - if ($this->_post_email === NULL){ |
|
| 172 | + if ($this->_post_email === NULL) { |
|
| 161 | 173 | // Fetch the SpotNab EmailID |
| 162 | 174 | $this->_post_email = trim($this->_pdo->getSetting('spotnabemail'))? |
| 163 | 175 | $this->_pdo->getSetting('spotnabemail'):NULL; |
| 164 | 176 | } |
| 165 | 177 | |
| 166 | - if ($this->_post_group === NULL){ |
|
| 178 | + if ($this->_post_group === NULL) { |
|
| 167 | 179 | // Fetch the SpotNab Usenet Group |
| 168 | 180 | $this->_post_group = trim($this->_pdo->getSetting('spotnabgroup'))? |
| 169 | 181 | $this->_pdo->getSetting('spotnabgroup'):NULL; |
@@ -172,14 +184,16 @@ discard block |
||
| 172 | 184 | // Public Key |
| 173 | 185 | $this->_ssl_pubkey = trim($this->_pdo->getSetting('spotnabsitepubkey'))? |
| 174 | 186 | $this->_pdo->getSetting('spotnabsitepubkey'):false; |
| 175 | - if($this->_ssl_pubkey) |
|
| 176 | - $this->_ssl_pubkey = $this->decompstr($this->_ssl_pubkey); |
|
| 187 | + if($this->_ssl_pubkey) { |
|
| 188 | + $this->_ssl_pubkey = $this->decompstr($this->_ssl_pubkey); |
|
| 189 | + } |
|
| 177 | 190 | |
| 178 | 191 | // Private Key |
| 179 | 192 | $this->_ssl_prvkey = trim($this->_pdo->getSetting('spotnabsiteprvkey'))? |
| 180 | 193 | $this->_pdo->getSetting('spotnabsiteprvkey'):false; |
| 181 | - if($this->_ssl_prvkey) |
|
| 182 | - $this->_ssl_prvkey = $this->decompstr($this->_ssl_prvkey); |
|
| 194 | + if($this->_ssl_prvkey) { |
|
| 195 | + $this->_ssl_prvkey = $this->decompstr($this->_ssl_prvkey); |
|
| 196 | + } |
|
| 183 | 197 | |
| 184 | 198 | // Track Discovery Article |
| 185 | 199 | $this->_discovery_lastarticle = intval($this->_pdo->getSetting('spotnablastarticle')); |
@@ -229,7 +243,7 @@ discard block |
||
| 229 | 243 | $this->_can_discover = (trim($this->_pdo->getSetting('spotnabdiscover')) == 1)? |
| 230 | 244 | true:false; |
| 231 | 245 | |
| 232 | - if (!$this->has_openssl()){ |
|
| 246 | + if (!$this->has_openssl()) { |
|
| 233 | 247 | // Can SpotNab even work; if not, we disable all flags |
| 234 | 248 | $this->_can_broadcast = false; |
| 235 | 249 | $this->_can_post = false; |
@@ -237,14 +251,16 @@ discard block |
||
| 237 | 251 | } |
| 238 | 252 | |
| 239 | 253 | // *********************************************************************** |
| 240 | - public function has_openssl(){ |
|
| 254 | + public function has_openssl() |
|
| 255 | + { |
|
| 241 | 256 | // return true if ssl is correctly configured and installed |
| 242 | 257 | // otherwise return a fail |
| 243 | 258 | return (is_readable(OPENSSL_CFG_PATH) && extension_loaded("openssl")); |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | // *********************************************************************** |
| 247 | - public function auto_clean($max_days=90){ |
|
| 262 | + public function auto_clean($max_days=90) |
|
| 263 | + { |
|
| 248 | 264 | // automatically sweep old sources lingering that have not shown any |
| 249 | 265 | // sort of life what-so-ever for more then 90 days |
| 250 | 266 | $sql = "DELETE FROM spotnabsources WHERE " |
@@ -310,7 +326,8 @@ discard block |
||
| 310 | 326 | } |
| 311 | 327 | |
| 312 | 328 | // *********************************************************************** |
| 313 | - public function soft_reset(){ |
|
| 329 | + public function soft_reset() |
|
| 330 | + { |
|
| 314 | 331 | // A harmless function that resets spotnab without losing sources |
| 315 | 332 | // Calling this function will reset spotnab to think: |
| 316 | 333 | // - it hasn't fetched anything yet from existing sources |
@@ -350,7 +367,8 @@ discard block |
||
| 350 | 367 | } |
| 351 | 368 | |
| 352 | 369 | // *********************************************************************** |
| 353 | - public function fetch_discovery($reftime = NULL, $retries=3){ |
|
| 370 | + public function fetch_discovery($reftime = NULL, $retries=3) |
|
| 371 | + { |
|
| 354 | 372 | $last = $first = NULL; |
| 355 | 373 | |
| 356 | 374 | // Return Value; Initialize it to Okay |
@@ -361,18 +379,18 @@ discard block |
||
| 361 | 379 | $inserted = 0; |
| 362 | 380 | $updated = 0; |
| 363 | 381 | |
| 364 | - if (!$this->_can_discover){ |
|
| 382 | + if (!$this->_can_discover) { |
|
| 365 | 383 | // discovery disabled |
| 366 | 384 | return false; |
| 367 | 385 | } |
| 368 | 386 | |
| 369 | - if($reftime === NULL){ |
|
| 387 | + if($reftime === NULL) { |
|
| 370 | 388 | $q = "SELECT updateddate FROM settings WHERE " |
| 371 | 389 | ."setting = 'spotnabdiscover'"; |
| 372 | 390 | $res = $this->_pdo->queryOneRow($q); |
| 373 | - if($res){ |
|
| 391 | + if($res) { |
|
| 374 | 392 | $reftime = $res['updateddate']; |
| 375 | - }else{ |
|
| 393 | + } else { |
|
| 376 | 394 | // Fetch local time (but look back the maximum duration |
| 377 | 395 | // that a discovery message can exist for |
| 378 | 396 | $reftime = $this->utc2local((time()-(SpotNab::POST_BROADCAST_INTERVAL))); |
@@ -380,12 +398,11 @@ discard block |
||
| 380 | 398 | } |
| 381 | 399 | |
| 382 | 400 | // Connect to server |
| 383 | - try{ |
|
| 401 | + try { |
|
| 384 | 402 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 385 | 403 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 386 | 404 | } |
| 387 | - } |
|
| 388 | - catch(\Exception $e){ |
|
| 405 | + } catch(\Exception $e) { |
|
| 389 | 406 | printf("Failed to connect to Usenet\n"); |
| 390 | 407 | return false; |
| 391 | 408 | } |
@@ -395,7 +412,7 @@ discard block |
||
| 395 | 412 | SpotNab::AUTODISCOVER_POST_GROUP); |
| 396 | 413 | |
| 397 | 414 | $first = $this->_discovery_lastarticle; |
| 398 | - if($first <= 0 || $first > $summary['last'] ){ |
|
| 415 | + if($first <= 0 || $first > $summary['last'] ) { |
|
| 399 | 416 | // Look back until reftime |
| 400 | 417 | $first = $this->_first_article_by_date( |
| 401 | 418 | SpotNab::AUTODISCOVER_POST_GROUP, |
@@ -403,7 +420,7 @@ discard block |
||
| 403 | 420 | ); |
| 404 | 421 | } |
| 405 | 422 | |
| 406 | - if($first === false){ |
|
| 423 | + if($first === false) { |
|
| 407 | 424 | // Fail |
| 408 | 425 | echo "Failed\n"; |
| 409 | 426 | return false; |
@@ -415,21 +432,19 @@ discard block |
||
| 415 | 432 | $total = abs($last-$first); |
| 416 | 433 | |
| 417 | 434 | // Select Group |
| 418 | - while($fetch_okay && $processed < $total) |
|
| 419 | - { |
|
| 420 | - try |
|
| 421 | - { |
|
| 435 | + while($fetch_okay && $processed < $total) { |
|
| 436 | + try { |
|
| 422 | 437 | // Prepare Initial Batch |
| 423 | - if ($total > SpotNab::FETCH_USENET_BATCH) |
|
| 424 | - $batch = $first + SpotNab::FETCH_USENET_BATCH; |
|
| 438 | + if ($total > SpotNab::FETCH_USENET_BATCH) { |
|
| 439 | + $batch = $first + SpotNab::FETCH_USENET_BATCH; |
|
| 440 | + } |
|
| 425 | 441 | |
| 426 | 442 | // Batch Processing |
| 427 | - while ($processed < $total) |
|
| 428 | - { |
|
| 443 | + while ($processed < $total) { |
|
| 429 | 444 | $headers = $this->_get_headers(SpotNab::AUTODISCOVER_POST_GROUP, |
| 430 | 445 | "$first-$batch", $retries); |
| 431 | 446 | |
| 432 | - if($headers === false){ |
|
| 447 | + if($headers === false) { |
|
| 433 | 448 | // Retry Atempts exausted |
| 434 | 449 | $fetch_okay = false; |
| 435 | 450 | break; |
@@ -437,8 +452,7 @@ discard block |
||
| 437 | 452 | |
| 438 | 453 | // Process the header batch |
| 439 | 454 | $saved = $this->process_discovery_headers($headers); |
| 440 | - if($saved !== false) |
|
| 441 | - { |
|
| 455 | + if($saved !== false) { |
|
| 442 | 456 | $inserted += $saved[0]; |
| 443 | 457 | $updated += $saved[1]; |
| 444 | 458 | } |
@@ -447,23 +461,23 @@ discard block |
||
| 447 | 461 | // Increment starting index |
| 448 | 462 | $first += ($batch-$first); |
| 449 | 463 | |
| 450 | - if ($last-$first >= SpotNab::FETCH_USENET_BATCH){ |
|
| 464 | + if ($last-$first >= SpotNab::FETCH_USENET_BATCH) { |
|
| 451 | 465 | // Fetch next batch |
| 452 | 466 | $batch = $first + SpotNab::FETCH_USENET_BATCH; |
| 453 | - }else{ |
|
| 467 | + } else { |
|
| 454 | 468 | $batch = $last; |
| 455 | 469 | } |
| 456 | 470 | //echo "$first-$batch, processed=$processed\n"; |
| 457 | 471 | //print_r($headers); |
| 458 | 472 | } |
| 459 | 473 | |
| 460 | - }catch(\Exception $e){ |
|
| 474 | + } catch(\Exception $e) { |
|
| 461 | 475 | // Reset Connection |
| 462 | 476 | $fetch_okay = $this->_nntpReset(SpotNab::AUTODISCOVER_POST_GROUP); |
| 463 | 477 | |
| 464 | 478 | // Track retry attempts |
| 465 | 479 | $retries--; |
| 466 | - if($retries <= 0){ |
|
| 480 | + if($retries <= 0) { |
|
| 467 | 481 | // Retry Atempts exausted |
| 468 | 482 | $fetch_okay = false; |
| 469 | 483 | break; |
@@ -485,17 +499,17 @@ discard block |
||
| 485 | 499 | } |
| 486 | 500 | |
| 487 | 501 | // *********************************************************************** |
| 488 | - public function auto_post_discovery($repost_sec = SpotNab::POST_BROADCAST_INTERVAL){ |
|
| 502 | + public function auto_post_discovery($repost_sec = SpotNab::POST_BROADCAST_INTERVAL) |
|
| 503 | + { |
|
| 489 | 504 | // performs a post discovery once the time in seconds has elapsed |
| 490 | 505 | $q = "SELECT updateddate FROM settings WHERE " |
| 491 | 506 | ."setting = 'spotnabbroadcast'"; |
| 492 | 507 | $res = $this->_pdo->queryOneRow($q); |
| 493 | 508 | $then = strtotime($res['updateddate']); |
| 494 | 509 | $now = time(); |
| 495 | - if(($now - $then) > $repost_sec){ |
|
| 510 | + if(($now - $then) > $repost_sec) { |
|
| 496 | 511 | // perform a post |
| 497 | - if($this->post_discovery()) |
|
| 498 | - { |
|
| 512 | + if($this->post_discovery()) { |
|
| 499 | 513 | // Update post time |
| 500 | 514 | $q = "Update settings SET updateddate = NOW() WHERE " |
| 501 | 515 | ."setting = 'spotnabbroadcast'"; |
@@ -505,30 +519,32 @@ discard block |
||
| 505 | 519 | } |
| 506 | 520 | |
| 507 | 521 | // *********************************************************************** |
| 508 | - public function post_discovery($reftime = NULL, $retries=3){ |
|
| 522 | + public function post_discovery($reftime = NULL, $retries=3) |
|
| 523 | + { |
|
| 509 | 524 | $reftime_local = $reftime; |
| 510 | 525 | $article = NULL; |
| 511 | 526 | $rc = new ReleaseComments(); |
| 512 | 527 | $us = new Users(); |
| 513 | 528 | |
| 514 | - if($reftime_local === NULL){ |
|
| 529 | + if($reftime_local === NULL) { |
|
| 515 | 530 | // Fetch local time |
| 516 | 531 | $reftime_local = $this->utc2local(); |
| 517 | 532 | } |
| 518 | 533 | // some error checking.... |
| 519 | - if(!$this->_can_broadcast){ |
|
| 534 | + if(!$this->_can_broadcast) { |
|
| 520 | 535 | // Broadcasting not possible |
| 521 | 536 | return false; |
| 522 | 537 | } |
| 523 | 538 | |
| 524 | 539 | // Generate keys if one doesn't exist |
| 525 | - if(!($this->_ssl_prvkey && $this->_ssl_pubkey)) |
|
| 526 | - if($this->keygen(false, true) === false) |
|
| 540 | + if(!($this->_ssl_prvkey && $this->_ssl_pubkey)) { |
|
| 541 | + if($this->keygen(false, true) === false) |
|
| 527 | 542 | return false; |
| 543 | + } |
|
| 528 | 544 | |
| 529 | 545 | // Get Discovery Private Key |
| 530 | 546 | $prvkey = $this->decompstr($this->_ssl_auto_prvkey); |
| 531 | - if (!$prvkey){ |
|
| 547 | + if (!$prvkey) { |
|
| 532 | 548 | // This is a serious problem because the hard-coded discovery |
| 533 | 549 | // key should always decrypt! |
| 534 | 550 | return false; |
@@ -576,14 +592,13 @@ discard block |
||
| 576 | 592 | SpotNab::AUTODISCOVER_POST_GROUP |
| 577 | 593 | ); |
| 578 | 594 | |
| 579 | - if($article === false){ |
|
| 595 | + if($article === false) { |
|
| 580 | 596 | echo "Failed.\n"; |
| 581 | 597 | return false; |
| 582 | 598 | } |
| 583 | 599 | |
| 584 | 600 | // Post message |
| 585 | - if ($this->_postArticle($article, $retries)) |
|
| 586 | - { |
|
| 601 | + if ($this->_postArticle($article, $retries)) { |
|
| 587 | 602 | // Post is good; update database |
| 588 | 603 | //echo "Done.\n"; |
| 589 | 604 | return true; |
@@ -604,7 +619,8 @@ discard block |
||
| 604 | 619 | * |
| 605 | 620 | * @return int |
| 606 | 621 | */ |
| 607 | - public function fetch($reftime = NULL, $retries = 3) { |
|
| 622 | + public function fetch($reftime = NULL, $retries = 3) |
|
| 623 | + { |
|
| 608 | 624 | |
| 609 | 625 | $first = NULL; |
| 610 | 626 | |
@@ -615,16 +631,16 @@ discard block |
||
| 615 | 631 | |
| 616 | 632 | // We set a cap on how many days in the past we look |
| 617 | 633 | $_max_age = time() - SpotNab::FETCH_MAXIMUM_AGE; |
| 618 | - if($reftime === NULL){ |
|
| 634 | + if($reftime === NULL) { |
|
| 619 | 635 | // Fetch local time (but look back X days) |
| 620 | 636 | $reftime = $this->utc2local($_max_age); |
| 621 | - }else{ |
|
| 637 | + } else { |
|
| 622 | 638 | // Someone specified a date range to query from |
| 623 | 639 | $backfill = true; |
| 624 | 640 | |
| 625 | - if(is_string($reftime)){ |
|
| 641 | + if(is_string($reftime)) { |
|
| 626 | 642 | $reftime = date("Y-m-d H:i:s", strtotime($reftime)); |
| 627 | - }else if(is_int($reftime)){ |
|
| 643 | + } else if(is_int($reftime)) { |
|
| 628 | 644 | $reftime = date("Y-m-d H:i:s", $reftime); |
| 629 | 645 | } |
| 630 | 646 | $_max_age = strtotime($reftime); |
@@ -637,12 +653,13 @@ discard block |
||
| 637 | 653 | $group_article_start = []; |
| 638 | 654 | $id_hash = []; |
| 639 | 655 | |
| 640 | - if(!count($res)) |
|
| 641 | - return true; |
|
| 656 | + if(!count($res)) { |
|
| 657 | + return true; |
|
| 658 | + } |
|
| 642 | 659 | |
| 643 | - foreach($res as $source){ |
|
| 660 | + foreach($res as $source) { |
|
| 644 | 661 | $ghash = trim($source['usenetgroup']); |
| 645 | - if(!array_key_exists($ghash, $group_hash)){ |
|
| 662 | + if(!array_key_exists($ghash, $group_hash)) { |
|
| 646 | 663 | // Because our results are sorted by group, if we enter |
| 647 | 664 | // here then we're processing a brand new group... |
| 648 | 665 | $group_hash[$ghash] = []; |
@@ -664,7 +681,7 @@ discard block |
||
| 664 | 681 | // UTC for processing. |
| 665 | 682 | $ref = $backfill?date("Y-m-d H:i:s", $_max_age):$source['lastupdate']; |
| 666 | 683 | |
| 667 | - if(!$ref){ |
|
| 684 | + if(!$ref) { |
|
| 668 | 685 | // We've never fetched from the group before, so we'll use |
| 669 | 686 | // the reftime passed to the function |
| 670 | 687 | $ref = $reftime; |
@@ -673,12 +690,13 @@ discard block |
||
| 673 | 690 | // Therefore, we need to take the lastupdate time and convert it to |
| 674 | 691 | // UTC for processing. |
| 675 | 692 | $article = abs(intval($source['lastarticle'])); |
| 676 | - if($article > 0){ |
|
| 677 | - if($group_article_start[$ghash] == 0) |
|
| 678 | - $group_article_start[$ghash] = $article; |
|
| 679 | - else |
|
| 680 | - $group_article_start[$ghash] = ($article < $group_article_start[$ghash])? |
|
| 693 | + if($article > 0) { |
|
| 694 | + if($group_article_start[$ghash] == 0) { |
|
| 695 | + $group_article_start[$ghash] = $article; |
|
| 696 | + } else { |
|
| 697 | + $group_article_start[$ghash] = ($article < $group_article_start[$ghash])? |
|
| 681 | 698 | $article:$group_article_start[$ghash]; |
| 699 | + } |
|
| 682 | 700 | } |
| 683 | 701 | |
| 684 | 702 | // Store id |
@@ -702,15 +720,16 @@ discard block |
||
| 702 | 720 | // We want to resort the internal arrays by they're ref time |
| 703 | 721 | // so that the oldest (longest without an update) is processed |
| 704 | 722 | // first |
| 705 | - foreach(array_keys($group_hash) as $key){ |
|
| 723 | + foreach(array_keys($group_hash) as $key) { |
|
| 706 | 724 | $_ref = []; |
| 707 | - foreach($group_hash[$key] as $id => $source){ |
|
| 725 | + foreach($group_hash[$key] as $id => $source) { |
|
| 708 | 726 | # Source Time (within reason) |
| 709 | - if($backfill) |
|
| 710 | - $_ref[$id] = $_max_age; |
|
| 711 | - else |
|
| 712 | - $_ref[$id] = |
|
| 727 | + if($backfill) { |
|
| 728 | + $_ref[$id] = $_max_age; |
|
| 729 | + } else { |
|
| 730 | + $_ref[$id] = |
|
| 713 | 731 | ($source['ref'] < $_max_age)?$_max_age:$source['ref']; |
| 732 | + } |
|
| 714 | 733 | } |
| 715 | 734 | // Sort results (oldest in time first) |
| 716 | 735 | array_multisort($_ref, SORT_ASC, $group_hash[$key]); |
@@ -719,12 +738,11 @@ discard block |
||
| 719 | 738 | // Now we fetch headers |
| 720 | 739 | |
| 721 | 740 | // Connect to server |
| 722 | - try{ |
|
| 741 | + try { |
|
| 723 | 742 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 724 | 743 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 725 | 744 | } |
| 726 | - } |
|
| 727 | - catch(\Exception $e){ |
|
| 745 | + } catch(\Exception $e) { |
|
| 728 | 746 | printf("Failed to connect to Usenet"); |
| 729 | 747 | return false; |
| 730 | 748 | } |
@@ -733,18 +751,18 @@ discard block |
||
| 733 | 751 | $inserted = 0; |
| 734 | 752 | $updated = 0; |
| 735 | 753 | |
| 736 | - foreach($group_hash as $group => $hash){ |
|
| 754 | + foreach($group_hash as $group => $hash) { |
|
| 737 | 755 | printf("Spotnab : %d source(s)...", count($hash)); |
| 738 | 756 | |
| 739 | 757 | $summary = $this->_nntp->selectGroup($group); |
| 740 | 758 | // Get our article id |
| 741 | 759 | $first = ($backfill)?0:$group_article_start[$group]; |
| 742 | - if($first == 0){ |
|
| 760 | + if($first == 0) { |
|
| 743 | 761 | // We can safely use the first $hash entry since we've |
| 744 | 762 | // already sorted it in ascending order above, so this |
| 745 | 763 | // is the time furthest back |
| 746 | 764 | $first = $this->_first_article_by_date($group, $hash[0]['ref']); |
| 747 | - if($first === false){ |
|
| 765 | + if($first === false) { |
|
| 748 | 766 | continue; |
| 749 | 767 | } |
| 750 | 768 | } |
@@ -755,21 +773,19 @@ discard block |
||
| 755 | 773 | $total = abs($last-$first); |
| 756 | 774 | |
| 757 | 775 | // Select Group |
| 758 | - while($fetch_okay && $processed < $total) |
|
| 759 | - { |
|
| 760 | - try |
|
| 761 | - { |
|
| 776 | + while($fetch_okay && $processed < $total) { |
|
| 777 | + try { |
|
| 762 | 778 | // Prepare Initial Batch |
| 763 | - if ($total > SpotNab::FETCH_USENET_BATCH) |
|
| 764 | - $batch = $first + SpotNab::FETCH_USENET_BATCH; |
|
| 779 | + if ($total > SpotNab::FETCH_USENET_BATCH) { |
|
| 780 | + $batch = $first + SpotNab::FETCH_USENET_BATCH; |
|
| 781 | + } |
|
| 765 | 782 | |
| 766 | 783 | // Batch Processing |
| 767 | - while ($processed>=0 && $processed < $total) |
|
| 768 | - { |
|
| 784 | + while ($processed>=0 && $processed < $total) { |
|
| 769 | 785 | $headers = $this->_get_headers($group, |
| 770 | 786 | "$first-$batch", $retries); |
| 771 | 787 | |
| 772 | - if($headers === false){ |
|
| 788 | + if($headers === false) { |
|
| 773 | 789 | // Retry Atempts exausted |
| 774 | 790 | $fetch_okay = false; |
| 775 | 791 | break; |
@@ -777,8 +793,7 @@ discard block |
||
| 777 | 793 | |
| 778 | 794 | // Process the header batch |
| 779 | 795 | $saved = $this->process_comment_headers($headers, $hash); |
| 780 | - if($saved !== false) |
|
| 781 | - { |
|
| 796 | + if($saved !== false) { |
|
| 782 | 797 | $inserted += $saved[0]; |
| 783 | 798 | $updated += $saved[1]; |
| 784 | 799 | } |
@@ -787,23 +802,23 @@ discard block |
||
| 787 | 802 | // Increment starting index |
| 788 | 803 | $first += ($batch-$first); |
| 789 | 804 | |
| 790 | - if ($last-$first >= SpotNab::FETCH_USENET_BATCH){ |
|
| 805 | + if ($last-$first >= SpotNab::FETCH_USENET_BATCH) { |
|
| 791 | 806 | // Fetch next batch |
| 792 | 807 | $batch = $first + SpotNab::FETCH_USENET_BATCH; |
| 793 | - }else{ |
|
| 808 | + } else { |
|
| 794 | 809 | $batch = $last; |
| 795 | 810 | } |
| 796 | 811 | //echo "$first-$batch, processed=$processed\n"; |
| 797 | 812 | //print_r($headers); |
| 798 | 813 | } |
| 799 | 814 | |
| 800 | - }catch(\Exception $e){ |
|
| 815 | + } catch(\Exception $e) { |
|
| 801 | 816 | // Reset Connection |
| 802 | 817 | $fetch_okay = $this->_nntpReset($group); |
| 803 | 818 | |
| 804 | 819 | // Track retry attempts |
| 805 | 820 | $retries--; |
| 806 | - if($retries <= 0){ |
|
| 821 | + if($retries <= 0) { |
|
| 807 | 822 | // Retry Atempts exausted |
| 808 | 823 | $fetch_okay = false; |
| 809 | 824 | break; |
@@ -818,14 +833,14 @@ discard block |
||
| 818 | 833 | } |
| 819 | 834 | |
| 820 | 835 | // Ensure We're not connected |
| 821 | - try{$this->_nntp->doQuit();} |
|
| 822 | - catch(\Exception $e) |
|
| 823 | - {/* do nothing */} |
|
| 836 | + try{$this->_nntp->doQuit();} catch(\Exception $e) { |
|
| 837 | +/* do nothing */} |
|
| 824 | 838 | |
| 825 | 839 | return $inserted + $updated; |
| 826 | 840 | } |
| 827 | 841 | |
| 828 | - public function processGID($limit=500, $batch=5000, $delete_broken_releases = false){ |
|
| 842 | + public function processGID($limit=500, $batch=5000, $delete_broken_releases = false) |
|
| 843 | + { |
|
| 829 | 844 | // Process until someone presses cntrl-c |
| 830 | 845 | |
| 831 | 846 | $nzb = new NZB(); |
@@ -839,46 +854,51 @@ discard block |
||
| 839 | 854 | .'WHERE gid IS NULL ORDER BY adddate DESC LIMIT %d,%d'; |
| 840 | 855 | $usql = "UPDATE releases SET gid = '%s' WHERE id = %d"; |
| 841 | 856 | |
| 842 | - while(1){ |
|
| 857 | + while(1) { |
|
| 843 | 858 | // finish |
| 844 | - if($limit > 0 && $processed >= $limit) |
|
| 845 | - break; |
|
| 859 | + if($limit > 0 && $processed >= $limit) { |
|
| 860 | + break; |
|
| 861 | + } |
|
| 846 | 862 | $batch=($limit > 0 && $batch > $limit)?$limit:$batch; |
| 847 | 863 | $res = $this->_pdo->query(sprintf($fsql, $offset, $batch)); |
| 848 | - if(!$res)break; |
|
| 849 | - if(count($res) <= 0)break; |
|
| 864 | + if(!$res) { |
|
| 865 | + break; |
|
| 866 | + } |
|
| 867 | + if(count($res) <= 0) { |
|
| 868 | + break; |
|
| 869 | + } |
|
| 850 | 870 | $offset += $batch; |
| 851 | 871 | |
| 852 | - foreach ($res as $r){ |
|
| 872 | + foreach ($res as $r) { |
|
| 853 | 873 | $nzbfile = $nzb->getNZBPath($r["guid"]); |
| 854 | - if($nzbfile === NULL){ |
|
| 874 | + if($nzbfile === NULL) { |
|
| 855 | 875 | continue; |
| 856 | 876 | } |
| 857 | 877 | |
| 858 | 878 | $nzbInfo = new NZBInfo(); |
| 859 | - if (!$nzbInfo->loadFromFile($nzbfile)) |
|
| 860 | - { |
|
| 861 | - if($delete_broken_releases){ |
|
| 879 | + if (!$nzbInfo->loadFromFile($nzbfile)) { |
|
| 880 | + if($delete_broken_releases) { |
|
| 862 | 881 | $this->releases->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage); |
| 863 | 882 | // Free the variable in an attempt to recover memory |
| 864 | 883 | echo '-'; |
| 865 | - }else{ |
|
| 884 | + } else { |
|
| 866 | 885 | // Skip over this one for future fetches |
| 867 | 886 | $offset++; |
| 868 | 887 | } |
| 869 | 888 | continue; |
| 870 | 889 | } |
| 871 | 890 | $gid = false; |
| 872 | - if (!empty($nzbInfo->gid)) |
|
| 873 | - $gid = $nzbInfo->gid; |
|
| 891 | + if (!empty($nzbInfo->gid)) { |
|
| 892 | + $gid = $nzbInfo->gid; |
|
| 893 | + } |
|
| 874 | 894 | // Free the variable in an attempt to recover memory |
| 875 | 895 | unset($nzbInfo); |
| 876 | 896 | |
| 877 | - if(!$gid){ |
|
| 878 | - if($delete_broken_releases){ |
|
| 897 | + if(!$gid) { |
|
| 898 | + if($delete_broken_releases) { |
|
| 879 | 899 | $this->releases->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage); |
| 880 | 900 | echo '-'; |
| 881 | - }else{ |
|
| 901 | + } else { |
|
| 882 | 902 | // Skip over this one for future fetches |
| 883 | 903 | $offset++; |
| 884 | 904 | } |
@@ -887,7 +907,7 @@ discard block |
||
| 887 | 907 | |
| 888 | 908 | // Update DB With Global Identifer |
| 889 | 909 | $ures = $this->_pdo->queryExec(sprintf("UPDATE releases SET gid = %s WHERE id = %d", $this->_pdo->escapeString($gid), $r['id'])); |
| 890 | - if($ures->rowCount() == 0){ |
|
| 910 | + if($ures->rowCount() == 0) { |
|
| 891 | 911 | printf("\nPostPrc : Failed to update: %s\n", $r['name']); |
| 892 | 912 | } |
| 893 | 913 | // make noise... |
@@ -906,13 +926,15 @@ discard block |
||
| 906 | 926 | ) |
| 907 | 927 | ); |
| 908 | 928 | $rows = $affected->rowCount(); |
| 909 | - if($rows > 0) |
|
| 910 | - $processed += $rows; |
|
| 929 | + if($rows > 0) { |
|
| 930 | + $processed += $rows; |
|
| 931 | + } |
|
| 911 | 932 | return $processed; |
| 912 | 933 | } |
| 913 | 934 | |
| 914 | 935 | // *********************************************************************** |
| 915 | - public function keygen($print = true, $force_regen = false){ |
|
| 936 | + public function keygen($print = true, $force_regen = false) |
|
| 937 | + { |
|
| 916 | 938 | // Simply generate a Public/Private Key pair if they don't already |
| 917 | 939 | // exist |
| 918 | 940 | |
@@ -920,17 +942,17 @@ discard block |
||
| 920 | 942 | // a few checks first to make sure it's safe to do so |
| 921 | 943 | $do_keygen = true; |
| 922 | 944 | |
| 923 | - if($force_regen === false){ |
|
| 945 | + if($force_regen === false) { |
|
| 924 | 946 | // Not forcing, so we immediately toggle the keygen |
| 925 | 947 | // flag, we'll toggle it back if we feel the need |
| 926 | 948 | $do_keygen = false; |
| 927 | 949 | |
| 928 | - if($this->_ssl_pubkey && $this->_ssl_prvkey){ |
|
| 950 | + if($this->_ssl_pubkey && $this->_ssl_prvkey) { |
|
| 929 | 951 | |
| 930 | 952 | $str_in = $this->getRandomStr(80); |
| 931 | 953 | $str_out = $this->decrypt($this->encrypt($str_in)); |
| 932 | 954 | |
| 933 | - if($str_in != $str_out){ |
|
| 955 | + if($str_in != $str_out) { |
|
| 934 | 956 | // Our key isn't good for nothin... |
| 935 | 957 | // regen a new one |
| 936 | 958 | $do_keygen = true; |
@@ -938,11 +960,10 @@ discard block |
||
| 938 | 960 | } |
| 939 | 961 | } |
| 940 | 962 | |
| 941 | - if($do_keygen) |
|
| 942 | - { |
|
| 963 | + if($do_keygen) { |
|
| 943 | 964 | // Set new Key |
| 944 | 965 | $keys = $this->_keygen(); |
| 945 | - if(is_array($keys)){ |
|
| 966 | + if(is_array($keys)) { |
|
| 946 | 967 | // Force New Username |
| 947 | 968 | $sql = sprintf("Update settings SET value = %s " |
| 948 | 969 | ."WHERE setting = 'spotnabuser'", |
@@ -973,13 +994,13 @@ discard block |
||
| 973 | 994 | $this->_post_email = trim($this->_pdo->getSetting('spotnabemail')); |
| 974 | 995 | $this->_ssl_pubkey = $this->decompstr($this->_pdo->getSetting('spotnabsitepubkey')); |
| 975 | 996 | $this->_ssl_prvkey = $this->decompstr($this->_pdo->getSetting('spotnabsiteprvkey')); |
| 976 | - }else{ |
|
| 997 | + } else { |
|
| 977 | 998 | // echo "Failed."; |
| 978 | 999 | return false; |
| 979 | 1000 | } |
| 980 | 1001 | } |
| 981 | 1002 | |
| 982 | - if($print){ |
|
| 1003 | + if($print) { |
|
| 983 | 1004 | printf("SPOTNAB USER : %s\n", $this->_post_user); |
| 984 | 1005 | printf("SPOTNAB EMAIL : %s\n", $this->_post_email); |
| 985 | 1006 | printf("SPOTNAB GROUP : %s\n", $this->_post_group); |
@@ -994,7 +1015,8 @@ discard block |
||
| 994 | 1015 | } |
| 995 | 1016 | |
| 996 | 1017 | // *********************************************************************** |
| 997 | - protected function _first_article_by_date($group, $refdate, $limit = SpotNab::FETCH_MAXIMUM_HEADERS, $retries=3){ |
|
| 1018 | + protected function _first_article_by_date($group, $refdate, $limit = SpotNab::FETCH_MAXIMUM_HEADERS, $retries=3) |
|
| 1019 | + { |
|
| 998 | 1020 | // fetches the first article starting at the time specified |
| 999 | 1021 | // by ref time. |
| 1000 | 1022 | // |
@@ -1021,12 +1043,12 @@ discard block |
||
| 1021 | 1043 | // no one is perfect right? |
| 1022 | 1044 | $curfew = 10; |
| 1023 | 1045 | |
| 1024 | - if(is_string($refdate)){ |
|
| 1046 | + if(is_string($refdate)) { |
|
| 1025 | 1047 | // Convert to Integer (Local Time) |
| 1026 | 1048 | $refdate = strtotime($refdate); |
| 1027 | 1049 | } |
| 1028 | 1050 | |
| 1029 | - while(($retries > 0) && ($interval > 0)){ |
|
| 1051 | + while(($retries > 0) && ($interval > 0)) { |
|
| 1030 | 1052 | $summary = $this->_nntp->selectGroup($group); |
| 1031 | 1053 | |
| 1032 | 1054 | $_last = $last = intval($summary['last']); |
@@ -1035,32 +1057,33 @@ discard block |
||
| 1035 | 1057 | $curdate = $lastdate = NULL; |
| 1036 | 1058 | $curid = $lastid = $first; |
| 1037 | 1059 | $interval = 0; |
| 1038 | - while($retries > 0){ |
|
| 1060 | + while($retries > 0) { |
|
| 1039 | 1061 | |
| 1040 | 1062 | // Save Last Interval |
| 1041 | 1063 | $lastinterval = $interval; |
| 1042 | 1064 | |
| 1043 | 1065 | // Adjust Interval |
| 1044 | - if(($last - $first) > 3) |
|
| 1045 | - $interval = floor(($last - $first)/2); |
|
| 1046 | - else |
|
| 1047 | - $interval = 1; |
|
| 1066 | + if(($last - $first) > 3) { |
|
| 1067 | + $interval = floor(($last - $first)/2); |
|
| 1068 | + } else { |
|
| 1069 | + $interval = 1; |
|
| 1070 | + } |
|
| 1048 | 1071 | |
| 1049 | - if($misses >= SpotNab::FETCH_MAX_MISSES){ |
|
| 1072 | + if($misses >= SpotNab::FETCH_MAX_MISSES) { |
|
| 1050 | 1073 | // Misses reached |
| 1051 | 1074 | $last = intval($summary['last']); |
| 1052 | 1075 | // Adjust pointer |
| 1053 | 1076 | $lastid = ($lastid=== false)?$first:$lastid; |
| 1054 | - if($lastid >0){ |
|
| 1055 | - if (($last-$lastid) > $limit){ |
|
| 1077 | + if($lastid >0) { |
|
| 1078 | + if (($last-$lastid) > $limit) { |
|
| 1056 | 1079 | // We exceeded our maximum header limit |
| 1057 | 1080 | // adjust accordingly |
| 1058 | 1081 | $lastid = $last - $limit; |
| 1059 | 1082 | } |
| 1060 | 1083 | echo " ".(abs($last-$lastid))." record(s) back."; |
| 1061 | 1084 | return $lastid; |
| 1062 | - }else{ |
|
| 1063 | - if (($_last-$last) > $limit){ |
|
| 1085 | + } else { |
|
| 1086 | + if (($_last-$last) > $limit) { |
|
| 1064 | 1087 | // We exceeded our maximum header limit |
| 1065 | 1088 | // adjust accordingly |
| 1066 | 1089 | $last = $_last - $limit; |
@@ -1072,14 +1095,15 @@ discard block |
||
| 1072 | 1095 | |
| 1073 | 1096 | // Swap |
| 1074 | 1097 | $lastdate = $curdate; |
| 1075 | - if($curid > 0) |
|
| 1076 | - $lastid = $curid; |
|
| 1098 | + if($curid > 0) { |
|
| 1099 | + $lastid = $curid; |
|
| 1100 | + } |
|
| 1077 | 1101 | |
| 1078 | 1102 | $msgs = $this->_get_headers( |
| 1079 | 1103 | $group, ($last-$interval), $retries); |
| 1080 | 1104 | |
| 1081 | - if($msgs === false){ |
|
| 1082 | - if (($_last-$last) > $limit){ |
|
| 1105 | + if($msgs === false) { |
|
| 1106 | + if (($_last-$last) > $limit) { |
|
| 1083 | 1107 | // We exceeded our maximum header limit |
| 1084 | 1108 | // adjust accordingly |
| 1085 | 1109 | $last = $_last - $limit; |
@@ -1094,18 +1118,18 @@ discard block |
||
| 1094 | 1118 | // Save Tracker |
| 1095 | 1119 | $curdate = strtotime($msgs[0]['Date']); |
| 1096 | 1120 | $curid = intval($msgs[0]['Number']); |
| 1097 | - if($curid <= 0){ |
|
| 1121 | + if($curid <= 0) { |
|
| 1098 | 1122 | $lastid = ($lastid=== false)?$first:$lastid; |
| 1099 | - if($lastid >0){ |
|
| 1100 | - if (($_last-$lastid) > $limit){ |
|
| 1123 | + if($lastid >0) { |
|
| 1124 | + if (($_last-$lastid) > $limit) { |
|
| 1101 | 1125 | // We exceeded our maximum header limit |
| 1102 | 1126 | // adjust accordingly |
| 1103 | 1127 | $lastid = $_last - $limit; |
| 1104 | 1128 | } |
| 1105 | 1129 | echo " ".(abs($_last-$lastid))." record(s) back."; |
| 1106 | 1130 | return $lastid; |
| 1107 | - }else{ |
|
| 1108 | - if (($_last-$last) > $limit){ |
|
| 1131 | + } else { |
|
| 1132 | + if (($_last-$last) > $limit) { |
|
| 1109 | 1133 | // We exceeded our maximum header limit |
| 1110 | 1134 | // adjust accordingly |
| 1111 | 1135 | $last = $_last - $limit; |
@@ -1115,12 +1139,11 @@ discard block |
||
| 1115 | 1139 | } |
| 1116 | 1140 | } |
| 1117 | 1141 | |
| 1118 | - if($interval == 1){ |
|
| 1142 | + if($interval == 1) { |
|
| 1119 | 1143 | // We're soo close now... |
| 1120 | 1144 | $curfew --; |
| 1121 | - if($curfew <= 0) |
|
| 1122 | - { |
|
| 1123 | - if (($_last-$curid) > $limit){ |
|
| 1145 | + if($curfew <= 0) { |
|
| 1146 | + if (($_last-$curid) > $limit) { |
|
| 1124 | 1147 | // We exceeded our maximum header limit |
| 1125 | 1148 | // adjust accordingly |
| 1126 | 1149 | $curid = $_last - $limit; |
@@ -1130,8 +1153,8 @@ discard block |
||
| 1130 | 1153 | return $curid; |
| 1131 | 1154 | } |
| 1132 | 1155 | |
| 1133 | - if($refdate > $curdate && $refdate > $lastdate){ |
|
| 1134 | - if (($_last-$curid) > $limit){ |
|
| 1156 | + if($refdate > $curdate && $refdate > $lastdate) { |
|
| 1157 | + if (($_last-$curid) > $limit) { |
|
| 1135 | 1158 | // We exceeded our maximum header limit |
| 1136 | 1159 | // adjust accordingly |
| 1137 | 1160 | $curid = $_last - $limit; |
@@ -1139,10 +1162,10 @@ discard block |
||
| 1139 | 1162 | // Found content |
| 1140 | 1163 | echo " ".($_last-$curid)." record(s) back."; |
| 1141 | 1164 | return $curid; |
| 1142 | - }else if($refdate > $curdate && $refdate > $lastdate){ |
|
| 1165 | + } else if($refdate > $curdate && $refdate > $lastdate) { |
|
| 1143 | 1166 | // Close... Shuffle forward a bit |
| 1144 | 1167 | $first+=2; |
| 1145 | - }else{ |
|
| 1168 | + } else { |
|
| 1146 | 1169 | // Slide window and try again |
| 1147 | 1170 | $last-=2; |
| 1148 | 1171 | } |
@@ -1151,13 +1174,15 @@ discard block |
||
| 1151 | 1174 | } |
| 1152 | 1175 | |
| 1153 | 1176 | // Make some noise |
| 1154 | - if($interval%2)echo "."; |
|
| 1177 | + if($interval%2) { |
|
| 1178 | + echo "."; |
|
| 1179 | + } |
|
| 1155 | 1180 | |
| 1156 | 1181 | // Adjust Boundaries |
| 1157 | - if($curdate > $refdate){ |
|
| 1182 | + if($curdate > $refdate) { |
|
| 1158 | 1183 | // We need to look further forward |
| 1159 | 1184 | $last = $curid+1; |
| 1160 | - }else if ($curdate <= $refdate){ |
|
| 1185 | + } else if ($curdate <= $refdate) { |
|
| 1161 | 1186 | // We need To look further back |
| 1162 | 1187 | $first = $curid-1; |
| 1163 | 1188 | } |
@@ -1168,7 +1193,8 @@ discard block |
||
| 1168 | 1193 | } |
| 1169 | 1194 | |
| 1170 | 1195 | // *********************************************************************** |
| 1171 | - public function process_comment_headers($headers, $group_hash, $save = true){ |
|
| 1196 | + public function process_comment_headers($headers, $group_hash, $save = true) |
|
| 1197 | + { |
|
| 1172 | 1198 | /* |
| 1173 | 1199 | * We iterate over the provided headers (generated by |
| 1174 | 1200 | * $this->_get_headers() to a structure that is at the very |
@@ -1209,7 +1235,7 @@ discard block |
||
| 1209 | 1235 | * ) |
| 1210 | 1236 | */ |
| 1211 | 1237 | |
| 1212 | - if(!count($group_hash)){ |
|
| 1238 | + if(!count($group_hash)) { |
|
| 1213 | 1239 | // Nothing to process |
| 1214 | 1240 | return []; |
| 1215 | 1241 | } |
@@ -1238,23 +1264,25 @@ discard block |
||
| 1238 | 1264 | $processed = 0; |
| 1239 | 1265 | $updates = 0; |
| 1240 | 1266 | $inserts = 0; |
| 1241 | - foreach ($headers as $header){ |
|
| 1267 | + foreach ($headers as $header) { |
|
| 1242 | 1268 | // Preform some general scanning the header to determine |
| 1243 | 1269 | // if it could possibly be a valid post. |
| 1244 | 1270 | if(!preg_match(SpotNab::FETCH_MSGID_REGEX, |
| 1245 | - $header['Message-ID'], $matches)){ |
|
| 1271 | + $header['Message-ID'], $matches)) { |
|
| 1246 | 1272 | continue; |
| 1247 | 1273 | } |
| 1248 | - if($matches['domain'] != SpotNab::SEGID_DOMAIN) |
|
| 1249 | - continue; |
|
| 1274 | + if($matches['domain'] != SpotNab::SEGID_DOMAIN) { |
|
| 1275 | + continue; |
|
| 1276 | + } |
|
| 1250 | 1277 | |
| 1251 | - if($matches['type'] != SpotNab::FETCH_COMMENT_TYPE) |
|
| 1252 | - continue; |
|
| 1278 | + if($matches['type'] != SpotNab::FETCH_COMMENT_TYPE) { |
|
| 1279 | + continue; |
|
| 1280 | + } |
|
| 1253 | 1281 | |
| 1254 | 1282 | // Now we check the subject line; it provides the first part of |
| 1255 | 1283 | // the key to determining if we should handle the message or not |
| 1256 | 1284 | if(!preg_match(SpotNab::FETCH_COMMENT_SUBJECT_REGEX, |
| 1257 | - $header['Subject'], $matches)){ |
|
| 1285 | + $header['Subject'], $matches)) { |
|
| 1258 | 1286 | continue; |
| 1259 | 1287 | } |
| 1260 | 1288 | |
@@ -1262,7 +1290,7 @@ discard block |
||
| 1262 | 1290 | $checksum = $matches['checksum']; |
| 1263 | 1291 | $refdate = $matches['utcref']; |
| 1264 | 1292 | $refdate_epoch = @strtotime($matches['utcref']. " UTC"); |
| 1265 | - if($refdate_epoch === false || $refdate_epoch < 0){ |
|
| 1293 | + if($refdate_epoch === false || $refdate_epoch < 0) { |
|
| 1266 | 1294 | // Bad time specified |
| 1267 | 1295 | continue; |
| 1268 | 1296 | } |
@@ -1271,20 +1299,21 @@ discard block |
||
| 1271 | 1299 | // assume the body will decode too (and won't be a waste of |
| 1272 | 1300 | // time to download it) |
| 1273 | 1301 | |
| 1274 | - foreach($group_hash as $hash){ |
|
| 1302 | + foreach($group_hash as $hash) { |
|
| 1275 | 1303 | // Track how many records we handled |
| 1276 | 1304 | $processed++; |
| 1277 | 1305 | |
| 1278 | 1306 | // First check the ref date... if it's newer then what we've |
| 1279 | 1307 | // already processed, then we'll just keep on chugging along. |
| 1280 | - if($refdate_epoch <= $hash['ref']){ |
|
| 1308 | + if($refdate_epoch <= $hash['ref']) { |
|
| 1281 | 1309 | continue; |
| 1282 | 1310 | } |
| 1283 | 1311 | |
| 1284 | 1312 | // Scan header information for supported matches |
| 1285 | 1313 | if(!preg_match('/^(?P<user>[^<]+)<(?P<email>[^>]+)>$/', |
| 1286 | - $header['From'], $matches)) |
|
| 1287 | - continue; |
|
| 1314 | + $header['From'], $matches)) { |
|
| 1315 | + continue; |
|
| 1316 | + } |
|
| 1288 | 1317 | |
| 1289 | 1318 | // Match against our sources posts |
| 1290 | 1319 | if(trim($matches['user']) != $hash['user']) { |
@@ -1338,7 +1367,7 @@ discard block |
||
| 1338 | 1367 | if(array_key_exists('comments',$body) && is_array($body['comments'])) { |
| 1339 | 1368 | $rc = new ReleaseComments(); |
| 1340 | 1369 | |
| 1341 | - foreach($body['comments'] as $comment){ |
|
| 1370 | + foreach($body['comments'] as $comment) { |
|
| 1342 | 1371 | |
| 1343 | 1372 | // Verify Comment is parseable |
| 1344 | 1373 | if(!is_array($comment)) { |
@@ -1402,7 +1431,7 @@ discard block |
||
| 1402 | 1431 | $hash['id'] |
| 1403 | 1432 | ) |
| 1404 | 1433 | ); |
| 1405 | - }else{ |
|
| 1434 | + } else { |
|
| 1406 | 1435 | // Debug non/save mode; mark update |
| 1407 | 1436 | $updates += 1; |
| 1408 | 1437 | } |
@@ -1418,7 +1447,8 @@ discard block |
||
| 1418 | 1447 | } |
| 1419 | 1448 | |
| 1420 | 1449 | // *********************************************************************** |
| 1421 | - public function process_discovery_headers($headers, $save = true){ |
|
| 1450 | + public function process_discovery_headers($headers, $save = true) |
|
| 1451 | + { |
|
| 1422 | 1452 | /* |
| 1423 | 1453 | * We iterate over the provided headers (generated by |
| 1424 | 1454 | * $this->_get_headers() to a structure that is at the very |
@@ -1461,26 +1491,28 @@ discard block |
||
| 1461 | 1491 | $processed = 0; |
| 1462 | 1492 | $inserts = 0; |
| 1463 | 1493 | $updates = 0; |
| 1464 | - foreach ($headers as $header){ |
|
| 1494 | + foreach ($headers as $header) { |
|
| 1465 | 1495 | // Preform some general scanning the header to determine |
| 1466 | 1496 | // if it could possibly be a valid post. |
| 1467 | 1497 | |
| 1468 | 1498 | // Now we check the subject line; it provides the first part of |
| 1469 | 1499 | // the key to determining if we should handle the message or not |
| 1470 | 1500 | if(!preg_match(SpotNab::FETCH_MSGID_REGEX, |
| 1471 | - $header['Message-ID'], $matches)){ |
|
| 1501 | + $header['Message-ID'], $matches)) { |
|
| 1472 | 1502 | continue; |
| 1473 | 1503 | } |
| 1474 | - if($matches['domain'] != SpotNab::SEGID_DOMAIN) |
|
| 1475 | - continue; |
|
| 1504 | + if($matches['domain'] != SpotNab::SEGID_DOMAIN) { |
|
| 1505 | + continue; |
|
| 1506 | + } |
|
| 1476 | 1507 | |
| 1477 | - if($matches['type'] != SpotNab::FETCH_DISCOVERY_TYPE) |
|
| 1478 | - continue; |
|
| 1508 | + if($matches['type'] != SpotNab::FETCH_DISCOVERY_TYPE) { |
|
| 1509 | + continue; |
|
| 1510 | + } |
|
| 1479 | 1511 | |
| 1480 | 1512 | // Now we check the subject line; it provides the first part of |
| 1481 | 1513 | // the key to determining if we should handle the message or not |
| 1482 | 1514 | if(!preg_match(SpotNab::FETCH_DISCOVERY_SUBJECT_REGEX, |
| 1483 | - $header['Subject'], $matches)){ |
|
| 1515 | + $header['Subject'], $matches)) { |
|
| 1484 | 1516 | continue; |
| 1485 | 1517 | } |
| 1486 | 1518 | |
@@ -1488,7 +1520,7 @@ discard block |
||
| 1488 | 1520 | $checksum = $matches['checksum']; |
| 1489 | 1521 | $refdate = $matches['utcref']; |
| 1490 | 1522 | $refdate_epoch = @strtotime($matches['utcref']. " UTC"); |
| 1491 | - if($refdate_epoch === false || $refdate_epoch < 0){ |
|
| 1523 | + if($refdate_epoch === false || $refdate_epoch < 0) { |
|
| 1492 | 1524 | // Bad time specified |
| 1493 | 1525 | continue; |
| 1494 | 1526 | } |
@@ -1502,14 +1534,17 @@ discard block |
||
| 1502 | 1534 | |
| 1503 | 1535 | // Scan header information for supported matches |
| 1504 | 1536 | if(!preg_match('/^(?P<user>[^<]+)<(?P<email>[^>]+)>$/', |
| 1505 | - $header['From'], $matches)) |
|
| 1506 | - continue; |
|
| 1537 | + $header['From'], $matches)) { |
|
| 1538 | + continue; |
|
| 1539 | + } |
|
| 1507 | 1540 | |
| 1508 | 1541 | // Match against our sources posts |
| 1509 | - if(trim($matches['user']) != SpotNab::AUTODISCOVER_POST_USER) |
|
| 1510 | - continue; |
|
| 1511 | - if(trim($matches['email']) != SpotNab::AUTODISCOVER_POST_EMAIL) |
|
| 1512 | - continue; |
|
| 1542 | + if(trim($matches['user']) != SpotNab::AUTODISCOVER_POST_USER) { |
|
| 1543 | + continue; |
|
| 1544 | + } |
|
| 1545 | + if(trim($matches['email']) != SpotNab::AUTODISCOVER_POST_EMAIL) { |
|
| 1546 | + continue; |
|
| 1547 | + } |
|
| 1513 | 1548 | |
| 1514 | 1549 | // If we reach here, we've found a header we can process |
| 1515 | 1550 | // The next step is to download the header's body |
@@ -1519,11 +1554,11 @@ discard block |
||
| 1519 | 1554 | // within the body matches that of the header... then we |
| 1520 | 1555 | // can start processing the guts of the body. |
| 1521 | 1556 | |
| 1522 | - if($save){ |
|
| 1557 | + if($save) { |
|
| 1523 | 1558 | // Download Body |
| 1524 | 1559 | $body = $this->_get_body($header['Group'], |
| 1525 | 1560 | $header['Message-ID']); |
| 1526 | - if($body === false){ |
|
| 1561 | + if($body === false) { |
|
| 1527 | 1562 | continue; |
| 1528 | 1563 | } |
| 1529 | 1564 | |
@@ -1532,27 +1567,36 @@ discard block |
||
| 1532 | 1567 | $body, |
| 1533 | 1568 | $this->decompstr($this->_ssl_auto_pubkey) |
| 1534 | 1569 | ); |
| 1535 | - if($body === false) |
|
| 1536 | - continue; // Decode failed |
|
| 1570 | + if($body === false) { |
|
| 1571 | + continue; |
|
| 1572 | + } |
|
| 1573 | + // Decode failed |
|
| 1537 | 1574 | |
| 1538 | 1575 | // Verify Body |
| 1539 | - if(!is_array($body)) |
|
| 1540 | - continue; // not any array |
|
| 1576 | + if(!is_array($body)) { |
|
| 1577 | + continue; |
|
| 1578 | + } |
|
| 1579 | + // not any array |
|
| 1541 | 1580 | |
| 1542 | - if(!(bool)count(array_filter(array_keys($body), 'is_string'))) |
|
| 1543 | - continue; // not an associative array |
|
| 1581 | + if(!(bool)count(array_filter(array_keys($body), 'is_string'))) { |
|
| 1582 | + continue; |
|
| 1583 | + } |
|
| 1584 | + // not an associative array |
|
| 1544 | 1585 | |
| 1545 | 1586 | if(!(array_key_exists('site', $body) && |
| 1546 | 1587 | array_key_exists('posts', $body) && |
| 1547 | 1588 | array_key_exists('comments', $body) && |
| 1548 | - array_key_exists('postdate_utc', $body))) |
|
| 1549 | - continue; // base structure missing |
|
| 1589 | + array_key_exists('postdate_utc', $body))) { |
|
| 1590 | + continue; |
|
| 1591 | + } |
|
| 1592 | + // base structure missing |
|
| 1550 | 1593 | |
| 1551 | 1594 | // Compare postdate_utc and ensure it matches header |
| 1552 | 1595 | // timestamp |
| 1553 | 1596 | if(preg_replace('/[^0-9]/', '', |
| 1554 | - $body['postdate_utc']) != $refdate) |
|
| 1555 | - continue; |
|
| 1597 | + $body['postdate_utc']) != $refdate) { |
|
| 1598 | + continue; |
|
| 1599 | + } |
|
| 1556 | 1600 | |
| 1557 | 1601 | $posts = $body['posts']; |
| 1558 | 1602 | $p_user = array_key_exists('user', $posts)?trim($posts['user']):NULL; |
@@ -1560,13 +1604,15 @@ discard block |
||
| 1560 | 1604 | $p_group = array_key_exists('group', $posts)?trim($posts['group']):NULL; |
| 1561 | 1605 | $p_key = array_key_exists('public_key', $posts)?trim($posts['public_key']):NULL; |
| 1562 | 1606 | |
| 1563 | - if(!($p_user && $p_email && $p_group && $p_key)) |
|
| 1564 | - // basic error checking |
|
| 1607 | + if(!($p_user && $p_email && $p_group && $p_key)) { |
|
| 1608 | + // basic error checking |
|
| 1565 | 1609 | continue; |
| 1610 | + } |
|
| 1566 | 1611 | |
| 1567 | 1612 | // Check to make sure the discovery isn't 'this' site |
| 1568 | - if($p_user == $this->_post_user && $p_email == $this->_post_email) |
|
| 1569 | - continue; |
|
| 1613 | + if($p_user == $this->_post_user && $p_email == $this->_post_email) { |
|
| 1614 | + continue; |
|
| 1615 | + } |
|
| 1570 | 1616 | |
| 1571 | 1617 | // Check that comment doesn't already exist |
| 1572 | 1618 | $res = $this->_pdo->queryOneRow(sprintf($sql_fnd_cmt, |
@@ -1575,12 +1621,13 @@ discard block |
||
| 1575 | 1621 | $this->_pdo->escapeString($p_group)) |
| 1576 | 1622 | ); |
| 1577 | 1623 | |
| 1578 | - if(!$res) |
|
| 1579 | - // Uh oh |
|
| 1624 | + if(!$res) { |
|
| 1625 | + // Uh oh |
|
| 1580 | 1626 | continue; |
| 1627 | + } |
|
| 1581 | 1628 | |
| 1582 | 1629 | // Store Results in DB |
| 1583 | - if(intval($res['cnt'])==0){ |
|
| 1630 | + if(intval($res['cnt'])==0) { |
|
| 1584 | 1631 | // Make some noise |
| 1585 | 1632 | echo '+'; |
| 1586 | 1633 | // Perform Insert |
@@ -1594,7 +1641,7 @@ discard block |
||
| 1594 | 1641 | $this->_pdo->escapeString($this->utc2local($refdate))) |
| 1595 | 1642 | ); |
| 1596 | 1643 | $inserts += 1; |
| 1597 | - }else{ |
|
| 1644 | + } else { |
|
| 1598 | 1645 | echo '.'; |
| 1599 | 1646 | $res = $this->_pdo->queryExec(sprintf($sql_upd_cmt, |
| 1600 | 1647 | $this->_pdo->escapeString($this->utc2local($refdate)), |
@@ -1609,22 +1656,23 @@ discard block |
||
| 1609 | 1656 | } |
| 1610 | 1657 | |
| 1611 | 1658 | // *********************************************************************** |
| 1612 | - protected function _get_body($group, $id, $retries=3){ |
|
| 1659 | + protected function _get_body($group, $id, $retries=3) |
|
| 1660 | + { |
|
| 1613 | 1661 | /* |
| 1614 | 1662 | * Fetch the body of a given Message-ID taken from the headers |
| 1615 | 1663 | * The function then returns the raw content |
| 1616 | 1664 | */ |
| 1617 | 1665 | |
| 1618 | 1666 | $matches = NULL; |
| 1619 | - if(preg_match("/^\s*<(.*)>\s*$/", $id, $matches)) |
|
| 1620 | - // Ensure we're always dealing with a properly |
|
| 1667 | + if(preg_match("/^\s*<(.*)>\s*$/", $id, $matches)) { |
|
| 1668 | + // Ensure we're always dealing with a properly |
|
| 1621 | 1669 | // formatted id |
| 1622 | 1670 | $id = $matches[1]; |
| 1671 | + } |
|
| 1623 | 1672 | |
| 1624 | 1673 | // The returned result will be stored in $raw |
| 1625 | 1674 | $raw = NULL; |
| 1626 | - do |
|
| 1627 | - { |
|
| 1675 | + do { |
|
| 1628 | 1676 | $raw = $this->_nntp->getBody("<".$id.">", true); |
| 1629 | 1677 | // Retrieved Data |
| 1630 | 1678 | return $raw; |
@@ -1634,7 +1682,8 @@ discard block |
||
| 1634 | 1682 | } |
| 1635 | 1683 | |
| 1636 | 1684 | // *********************************************************************** |
| 1637 | - protected function _get_headers($group, $range, $retries=3, $sort = true){ |
|
| 1685 | + protected function _get_headers($group, $range, $retries=3, $sort = true) |
|
| 1686 | + { |
|
| 1638 | 1687 | /* |
| 1639 | 1688 | * |
| 1640 | 1689 | * There is to much involved with fetching article headers |
@@ -1656,8 +1705,7 @@ discard block |
||
| 1656 | 1705 | $min_headers = ['Number', 'Subject', 'From', 'Date', |
| 1657 | 1706 | 'Message-ID', 'Bytes', 'Lines' |
| 1658 | 1707 | ]; |
| 1659 | - do |
|
| 1660 | - { |
|
| 1708 | + do { |
|
| 1661 | 1709 | $msgs = $this->_nntp->getOverview($range, true, false); |
| 1662 | 1710 | // If we get here, then we fetched the header block okay |
| 1663 | 1711 | |
@@ -1665,30 +1713,36 @@ discard block |
||
| 1665 | 1713 | // just report what it found.. (nothing). We do this because |
| 1666 | 1714 | // NNTP::isError() never threw, so the response has to be valid |
| 1667 | 1715 | // even though it's inconsistent |
| 1668 | - if(!$msgs)return []; |
|
| 1669 | - if(!is_array($msgs))return []; |
|
| 1716 | + if(!$msgs) { |
|
| 1717 | + return []; |
|
| 1718 | + } |
|
| 1719 | + if(!is_array($msgs)) { |
|
| 1720 | + return []; |
|
| 1721 | + } |
|
| 1670 | 1722 | |
| 1671 | 1723 | // For whatever reason, we sometimes get an array of |
| 1672 | 1724 | // associative array returned, and all other times we just |
| 1673 | 1725 | // get an associative array. Convert the associative array |
| 1674 | 1726 | // if we get one to an array of associative array just to |
| 1675 | 1727 | // simplify the response and make it esier to work with |
| 1676 | - if((bool)count(array_filter(array_keys($msgs), 'is_string'))){ |
|
| 1728 | + if((bool)count(array_filter(array_keys($msgs), 'is_string'))) { |
|
| 1677 | 1729 | // convert to an array of assocative array |
| 1678 | 1730 | $msgs = [$msgs]; |
| 1679 | 1731 | } |
| 1680 | 1732 | |
| 1681 | - for($i=0;$i<count($msgs);$i++){ |
|
| 1733 | + for($i=0;$i<count($msgs);$i++) { |
|
| 1682 | 1734 | $skip = false; |
| 1683 | - foreach($min_headers as $key){ |
|
| 1684 | - if(!array_key_exists($key, $msgs[$i])){ |
|
| 1735 | + foreach($min_headers as $key) { |
|
| 1736 | + if(!array_key_exists($key, $msgs[$i])) { |
|
| 1685 | 1737 | unset($msgs[$i]); |
| 1686 | 1738 | $i--; |
| 1687 | 1739 | $skip = true; |
| 1688 | 1740 | break; |
| 1689 | 1741 | } |
| 1690 | 1742 | } |
| 1691 | - if($skip)continue; |
|
| 1743 | + if($skip) { |
|
| 1744 | + continue; |
|
| 1745 | + } |
|
| 1692 | 1746 | |
| 1693 | 1747 | // Update Record With Epoch Value (# of sec from Jan, 1980) |
| 1694 | 1748 | $epoch[$i] = $msgs[$i]['Epoch'] = strtotime($msgs[$i]['Date']); |
@@ -1697,11 +1751,12 @@ discard block |
||
| 1697 | 1751 | $epoch[$i] = $msgs[$i]['Group'] = $group; |
| 1698 | 1752 | } |
| 1699 | 1753 | |
| 1700 | - if($sort && count($msgs)>1) |
|
| 1701 | - // Content is already sorted by articles, but if the |
|
| 1754 | + if($sort && count($msgs)>1) { |
|
| 1755 | + // Content is already sorted by articles, but if the |
|
| 1702 | 1756 | // sort flag is specified, then content is re-sorted by the |
| 1703 | 1757 | // messages stored epoch time |
| 1704 | 1758 | array_multisort($epoch, SORT_ASC, $msgs); |
| 1759 | + } |
|
| 1705 | 1760 | |
| 1706 | 1761 | return $msgs; |
| 1707 | 1762 | |
@@ -1711,7 +1766,8 @@ discard block |
||
| 1711 | 1766 | } |
| 1712 | 1767 | |
| 1713 | 1768 | // *********************************************************************** |
| 1714 | - public function post($reftime = NULL, $retries=3){ |
|
| 1769 | + public function post($reftime = NULL, $retries=3) |
|
| 1770 | + { |
|
| 1715 | 1771 | /* |
| 1716 | 1772 | * This function posts to usenet if there are any new updates |
| 1717 | 1773 | * to report that are flagged for transmit. |
@@ -1720,14 +1776,14 @@ discard block |
||
| 1720 | 1776 | */ |
| 1721 | 1777 | |
| 1722 | 1778 | // Make sure we can post |
| 1723 | - if(!$this->_can_post){ |
|
| 1779 | + if(!$this->_can_post) { |
|
| 1724 | 1780 | // Disabled |
| 1725 | 1781 | return false; |
| 1726 | 1782 | } |
| 1727 | 1783 | |
| 1728 | 1784 | $reftime_local = $reftime; |
| 1729 | 1785 | $article = NULL; |
| 1730 | - if($reftime_local === NULL){ |
|
| 1786 | + if($reftime_local === NULL) { |
|
| 1731 | 1787 | // Fetch local time |
| 1732 | 1788 | $reftime_local = $this->utc2local(); |
| 1733 | 1789 | } |
@@ -1742,26 +1798,25 @@ discard block |
||
| 1742 | 1798 | ]; |
| 1743 | 1799 | |
| 1744 | 1800 | // Store Comments |
| 1745 | - while(($data = $this->unPostedComments()) !== NULL) |
|
| 1746 | - { |
|
| 1801 | + while(($data = $this->unPostedComments()) !== NULL) { |
|
| 1747 | 1802 | $message['comments'] = $data['comments']; |
| 1748 | 1803 | $sql = sprintf("UPDATE release_comments " |
| 1749 | 1804 | ."SET issynced = 1 WHERE id IN (%s)", |
| 1750 | 1805 | implode(",", $data['ids'])); |
| 1751 | 1806 | |
| 1752 | 1807 | // Generate keys if one doesn't exist |
| 1753 | - if(!($this->_ssl_prvkey && $this->_ssl_pubkey)) |
|
| 1754 | - { |
|
| 1755 | - if($this->keygen(false, true) !== false) |
|
| 1756 | - // Post a discovery message if enabled |
|
| 1808 | + if(!($this->_ssl_prvkey && $this->_ssl_pubkey)) { |
|
| 1809 | + if($this->keygen(false, true) !== false) { |
|
| 1810 | + // Post a discovery message if enabled |
|
| 1757 | 1811 | $this->post_discovery(); |
| 1758 | - else |
|
| 1759 | - return false; |
|
| 1812 | + } else { |
|
| 1813 | + return false; |
|
| 1814 | + } |
|
| 1760 | 1815 | } |
| 1761 | 1816 | |
| 1762 | 1817 | // Encode Message so it can be posted |
| 1763 | 1818 | $article = $this->encodePost($message, $reftime_local); |
| 1764 | - if($article === false){ |
|
| 1819 | + if($article === false) { |
|
| 1765 | 1820 | echo "Failed.\n"; |
| 1766 | 1821 | return false; |
| 1767 | 1822 | } |
@@ -1769,8 +1824,7 @@ discard block |
||
| 1769 | 1824 | |
| 1770 | 1825 | // Post message |
| 1771 | 1826 | printf("Spotnab : %d posting ...\n", count($message['comments'])); |
| 1772 | - if (!$this->_postArticle($article, $retries)) |
|
| 1773 | - { |
|
| 1827 | + if (!$this->_postArticle($article, $retries)) { |
|
| 1774 | 1828 | // Post is good; update database |
| 1775 | 1829 | $res = $this->_pdo->queryExec($sql); |
| 1776 | 1830 | echo "Failed.\n"; |
@@ -1789,7 +1843,7 @@ discard block |
||
| 1789 | 1843 | private function _postArticle ($article, $retries=3) |
| 1790 | 1844 | { |
| 1791 | 1845 | // Extract message id |
| 1792 | - if(!preg_match('/Message-ID: <(?P<id>[^>]+)>/', $article[0], $matches)){ |
|
| 1846 | + if(!preg_match('/Message-ID: <(?P<id>[^>]+)>/', $article[0], $matches)) { |
|
| 1793 | 1847 | // we couldn't extract the message id |
| 1794 | 1848 | return false; |
| 1795 | 1849 | } |
@@ -1800,12 +1854,10 @@ discard block |
||
| 1800 | 1854 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 1801 | 1855 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 1802 | 1856 | } |
| 1803 | - while($retries > 0) |
|
| 1804 | - { |
|
| 1805 | - try |
|
| 1806 | - { |
|
| 1857 | + while($retries > 0) { |
|
| 1858 | + try { |
|
| 1807 | 1859 | $summary = $this->_nntp->selectGroup($this->_post_group); |
| 1808 | - if(NNTP::isError($summary)){ |
|
| 1860 | + if(NNTP::isError($summary)) { |
|
| 1809 | 1861 | $summary = $this->_nntpReset($this->_post_group); |
| 1810 | 1862 | $retries--; |
| 1811 | 1863 | continue; |
@@ -1821,11 +1873,10 @@ discard block |
||
| 1821 | 1873 | // Actually send the article |
| 1822 | 1874 | $_err = $this->_nntp->cmdPost2($article); |
| 1823 | 1875 | |
| 1824 | - }catch(\Exception $e){ |
|
| 1876 | + } catch(\Exception $e) { |
|
| 1825 | 1877 | // Ensure We're not connected |
| 1826 | - try{$this->_nntp->doQuit();} |
|
| 1827 | - catch(\Exception $e) |
|
| 1828 | - {/* do nothing */} |
|
| 1878 | + try{$this->_nntp->doQuit();} catch(\Exception $e) { |
|
| 1879 | +/* do nothing */} |
|
| 1829 | 1880 | |
| 1830 | 1881 | // Post failed |
| 1831 | 1882 | $retries--; |
@@ -1850,17 +1901,15 @@ discard block |
||
| 1850 | 1901 | private function _nntpReset ($group = NULL) |
| 1851 | 1902 | { |
| 1852 | 1903 | // Reset Connection |
| 1853 | - try{$this->_nntp->doQuit();} |
|
| 1854 | - catch(\Exception $e) |
|
| 1855 | - {/* do nothing */} |
|
| 1904 | + try{$this->_nntp->doQuit();} catch(\Exception $e) { |
|
| 1905 | +/* do nothing */} |
|
| 1856 | 1906 | |
| 1857 | 1907 | // Attempt to reconnect |
| 1858 | 1908 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 1859 | 1909 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 1860 | 1910 | } |
| 1861 | 1911 | |
| 1862 | - if($group !== NULL) |
|
| 1863 | - { |
|
| 1912 | + if($group !== NULL) { |
|
| 1864 | 1913 | // Reselect group if specified |
| 1865 | 1914 | $summary = $this->_nntp->selectGroup($this->_post_group); |
| 1866 | 1915 | return $summary; |
@@ -1869,19 +1918,22 @@ discard block |
||
| 1869 | 1918 | } |
| 1870 | 1919 | |
| 1871 | 1920 | // *********************************************************************** |
| 1872 | - public function getRandomStr($len) { |
|
| 1921 | + public function getRandomStr($len) |
|
| 1922 | + { |
|
| 1873 | 1923 | // Valid Characters |
| 1874 | 1924 | static $vc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
| 1875 | 1925 | |
| 1876 | 1926 | $unique = ''; |
| 1877 | - for($i = 0; $i < $len; $i++) |
|
| 1878 | - $unique .= $vc[mt_rand(0, strlen($vc) - 1)]; |
|
| 1927 | + for($i = 0; $i < $len; $i++) { |
|
| 1928 | + $unique .= $vc[mt_rand(0, strlen($vc) - 1)]; |
|
| 1929 | + } |
|
| 1879 | 1930 | |
| 1880 | 1931 | return $unique; |
| 1881 | 1932 | } |
| 1882 | 1933 | |
| 1883 | 1934 | // *********************************************************************** |
| 1884 | - public function decodePost($message, $key = NULL, $decrypt = true) { |
|
| 1935 | + public function decodePost($message, $key = NULL, $decrypt = true) |
|
| 1936 | + { |
|
| 1885 | 1937 | |
| 1886 | 1938 | // Decode Yenc |
| 1887 | 1939 | $message = Yenc::decode($message); |
@@ -1889,27 +1941,28 @@ discard block |
||
| 1889 | 1941 | // Decompress Messsage |
| 1890 | 1942 | $message = @gzuncompress($message); |
| 1891 | 1943 | |
| 1892 | - if ($key === NULL) |
|
| 1893 | - $key = $this->_ssl_pubkey; |
|
| 1944 | + if ($key === NULL) { |
|
| 1945 | + $key = $this->_ssl_pubkey; |
|
| 1946 | + } |
|
| 1894 | 1947 | |
| 1895 | 1948 | // Decrypt Message |
| 1896 | - if($decrypt){ |
|
| 1949 | + if($decrypt) { |
|
| 1897 | 1950 | $message = $this->decrypt($message, $key); |
| 1898 | - if($message === false){ |
|
| 1951 | + if($message === false) { |
|
| 1899 | 1952 | // fail |
| 1900 | 1953 | return false; |
| 1901 | 1954 | } |
| 1902 | - }else{ |
|
| 1955 | + } else { |
|
| 1903 | 1956 | // Convert from base64 |
| 1904 | 1957 | $message = base64_decode($message); |
| 1905 | - if($message === false){ |
|
| 1958 | + if($message === false) { |
|
| 1906 | 1959 | // Fail |
| 1907 | 1960 | return false; |
| 1908 | 1961 | } |
| 1909 | 1962 | } |
| 1910 | 1963 | |
| 1911 | 1964 | $message = json_decode($message, true); |
| 1912 | - if($message === false){ |
|
| 1965 | + if($message === false) { |
|
| 1913 | 1966 | // Fail |
| 1914 | 1967 | return false; |
| 1915 | 1968 | } |
@@ -1921,7 +1974,8 @@ discard block |
||
| 1921 | 1974 | public function encodePost($message, $reftime = NULL, $debug = false, |
| 1922 | 1975 | $prvkey = NULL, $passphrase = NULL, $encrypt = true, |
| 1923 | 1976 | $msgtype = SpotNab::FETCH_COMMENT_TYPE, |
| 1924 | - $user = NULL, $email = NULL, $group = NULL) { |
|
| 1977 | + $user = NULL, $email = NULL, $group = NULL) |
|
| 1978 | + { |
|
| 1925 | 1979 | /* |
| 1926 | 1980 | |
| 1927 | 1981 | Assembles and encodes a message ready to be posted onto |
@@ -1948,13 +2002,13 @@ discard block |
||
| 1948 | 2002 | SpotNab::SEGID_DOMAIN |
| 1949 | 2003 | ); |
| 1950 | 2004 | |
| 1951 | - if(!is_string($message)){ |
|
| 2005 | + if(!is_string($message)) { |
|
| 1952 | 2006 | // If message is not already in string format, then |
| 1953 | 2007 | // it's in it's assembled mixed array format... we |
| 1954 | 2008 | // need to convert it to json before proceeding |
| 1955 | 2009 | $message = json_encode($message, JSON_HEX_TAG|JSON_HEX_APOS| |
| 1956 | 2010 | JSON_HEX_QUOT|JSON_HEX_AMP|JSON_UNESCAPED_UNICODE); |
| 1957 | - if($message === false){ |
|
| 2011 | + if($message === false) { |
|
| 1958 | 2012 | // Fail |
| 1959 | 2013 | return false; |
| 1960 | 2014 | } |
@@ -1966,14 +2020,14 @@ discard block |
||
| 1966 | 2020 | // [1] => 'Message Body' |
| 1967 | 2021 | // ); |
| 1968 | 2022 | |
| 1969 | - if($encrypt){ |
|
| 2023 | + if($encrypt) { |
|
| 1970 | 2024 | // Encrypt Message |
| 1971 | 2025 | $message = $this->encrypt($message, $prvkey, $passphrase); |
| 1972 | - if($message === false){ |
|
| 2026 | + if($message === false) { |
|
| 1973 | 2027 | // fail |
| 1974 | 2028 | return false; |
| 1975 | 2029 | } |
| 1976 | - }else{ |
|
| 2030 | + } else { |
|
| 1977 | 2031 | // Convert to base64 |
| 1978 | 2032 | $message = base64_encode($message); |
| 1979 | 2033 | } |
@@ -1999,12 +2053,15 @@ discard block |
||
| 1999 | 2053 | $reftime |
| 2000 | 2054 | ); |
| 2001 | 2055 | |
| 2002 | - if($user === NULL) |
|
| 2003 | - $user = trim($this->_post_user); |
|
| 2004 | - if($email === NULL) |
|
| 2005 | - $email = trim($this->_post_email); |
|
| 2006 | - if($group === NULL) |
|
| 2007 | - $group = trim($this->_post_group); |
|
| 2056 | + if($user === NULL) { |
|
| 2057 | + $user = trim($this->_post_user); |
|
| 2058 | + } |
|
| 2059 | + if($email === NULL) { |
|
| 2060 | + $email = trim($this->_post_email); |
|
| 2061 | + } |
|
| 2062 | + if($group === NULL) { |
|
| 2063 | + $group = trim($this->_post_group); |
|
| 2064 | + } |
|
| 2008 | 2065 | |
| 2009 | 2066 | $header = "Subject: " . $subject . "\r\n"; |
| 2010 | 2067 | $header .= "Newsgroups: " . $group . "\r\n"; |
@@ -2021,7 +2078,7 @@ discard block |
||
| 2021 | 2078 | // Assemble Article in structure NNTP expects |
| 2022 | 2079 | $article = [$header, $message]; |
| 2023 | 2080 | |
| 2024 | - if($debug){ |
|
| 2081 | + if($debug) { |
|
| 2025 | 2082 | // Append some debug data to the article |
| 2026 | 2083 | $article[] = [ |
| 2027 | 2084 | 'Number' => 1234, |
@@ -2040,7 +2097,8 @@ discard block |
||
| 2040 | 2097 | } |
| 2041 | 2098 | |
| 2042 | 2099 | // *********************************************************************** |
| 2043 | - public function unPostedComments($limit = SpotNab::POST_MAXIMUM_COMMENTS) { |
|
| 2100 | + public function unPostedComments($limit = SpotNab::POST_MAXIMUM_COMMENTS) |
|
| 2101 | + { |
|
| 2044 | 2102 | /* |
| 2045 | 2103 | * This function returns a list of comments that have not been |
| 2046 | 2104 | * otherwise posted to usenet. |
@@ -2060,29 +2118,32 @@ discard block |
||
| 2060 | 2118 | ."LIMIT %d", $limit); |
| 2061 | 2119 | |
| 2062 | 2120 | $res = $this->_pdo->query($sql); |
| 2063 | - if(!$res) |
|
| 2064 | - return NULL; |
|
| 2121 | + if(!$res) { |
|
| 2122 | + return NULL; |
|
| 2123 | + } |
|
| 2065 | 2124 | |
| 2066 | 2125 | // Now we prepare a comments array to return with |
| 2067 | 2126 | $comments = []; |
| 2068 | 2127 | $ids = []; |
| 2069 | 2128 | |
| 2070 | - foreach($res as $comment){ |
|
| 2129 | + foreach($res as $comment) { |
|
| 2071 | 2130 | // If we don't have a gid then we can't make the post; |
| 2072 | 2131 | // the user hasn't set up there database to store the gid's |
| 2073 | 2132 | // correctly |
| 2074 | 2133 | |
| 2075 | - if(empty($comment['gid'])) |
|
| 2076 | - continue; |
|
| 2134 | + if(empty($comment['gid'])) { |
|
| 2135 | + continue; |
|
| 2136 | + } |
|
| 2077 | 2137 | |
| 2078 | 2138 | // Privacy options (scramble username or not) |
| 2079 | - if ($this->_post_privacy) |
|
| 2080 | - $username = sprintf( |
|
| 2139 | + if ($this->_post_privacy) { |
|
| 2140 | + $username = sprintf( |
|
| 2081 | 2141 | "sn-%s", |
| 2082 | 2142 | substr(md5($comment['username'].$this->_pdo->getSetting('siteseed')), 0, 6) |
| 2083 | 2143 | ); |
| 2084 | - else |
|
| 2085 | - $username = $comment['username']; |
|
| 2144 | + } else { |
|
| 2145 | + $username = $comment['username']; |
|
| 2146 | + } |
|
| 2086 | 2147 | |
| 2087 | 2148 | // Hash a unique Comment id to associate with this message |
| 2088 | 2149 | $cid = md5($comment['id'].$comment['username'].$comment['createddate'].$comment['host']); |
@@ -2113,7 +2174,8 @@ discard block |
||
| 2113 | 2174 | } |
| 2114 | 2175 | |
| 2115 | 2176 | // *********************************************************************** |
| 2116 | - public function utc2local($utc = NULL, $format="Y-m-d H:i:s") { |
|
| 2177 | + public function utc2local($utc = NULL, $format="Y-m-d H:i:s") |
|
| 2178 | + { |
|
| 2117 | 2179 | /* |
| 2118 | 2180 | * Takes a utc time as input and outputs local |
| 2119 | 2181 | * If no argument is specified then current local |
@@ -2128,7 +2190,8 @@ discard block |
||
| 2128 | 2190 | } |
| 2129 | 2191 | |
| 2130 | 2192 | // *********************************************************************** |
| 2131 | - public function local2utc($local = NULL, $format="Y-m-d H:i:s") { |
|
| 2193 | + public function local2utc($local = NULL, $format="Y-m-d H:i:s") |
|
| 2194 | + { |
|
| 2132 | 2195 | /* |
| 2133 | 2196 | * Takes a local time as input and outputs UTC |
| 2134 | 2197 | * If no argument is specified then current UTC |
@@ -2183,31 +2246,36 @@ discard block |
||
| 2183 | 2246 | } |
| 2184 | 2247 | |
| 2185 | 2248 | // *********************************************************************** |
| 2186 | - public function encrypt ($source, $prvkey = NULL, $passphrase = NULL){ |
|
| 2249 | + public function encrypt ($source, $prvkey = NULL, $passphrase = NULL) |
|
| 2250 | + { |
|
| 2187 | 2251 | // Encryption performed using private key |
| 2188 | - if($prvkey === NULL) |
|
| 2189 | - // Default Key if none is specified |
|
| 2252 | + if($prvkey === NULL) { |
|
| 2253 | + // Default Key if none is specified |
|
| 2190 | 2254 | $prvkey = $this->_ssl_prvkey; |
| 2255 | + } |
|
| 2191 | 2256 | |
| 2192 | - if(!$prvkey) |
|
| 2193 | - // Still no key... |
|
| 2257 | + if(!$prvkey) { |
|
| 2258 | + // Still no key... |
|
| 2194 | 2259 | return false; |
| 2260 | + } |
|
| 2195 | 2261 | |
| 2196 | - if(!function_exists('openssl_get_privatekey')) |
|
| 2197 | - return false; |
|
| 2262 | + if(!function_exists('openssl_get_privatekey')) { |
|
| 2263 | + return false; |
|
| 2264 | + } |
|
| 2198 | 2265 | |
| 2199 | 2266 | // Load Public Key into array |
| 2200 | 2267 | $crypttext=''; |
| 2201 | 2268 | $pkey = openssl_get_privatekey($prvkey, $passphrase); |
| 2202 | - if($pkey === false) |
|
| 2203 | - // bad key |
|
| 2269 | + if($pkey === false) { |
|
| 2270 | + // bad key |
|
| 2204 | 2271 | return false; |
| 2272 | + } |
|
| 2205 | 2273 | |
| 2206 | 2274 | $batch = $len = strlen($source); |
| 2207 | 2275 | $ptr = 0; |
| 2208 | 2276 | $encrypted = ''; |
| 2209 | 2277 | |
| 2210 | - while($len > 0){ |
|
| 2278 | + while($len > 0) { |
|
| 2211 | 2279 | // Prepare batch size |
| 2212 | 2280 | $batch = (($len - SpotNab::SSL_MAX_BUF_LEN) > 0) ? SpotNab::SSL_MAX_BUF_LEN : $len; |
| 2213 | 2281 | |
@@ -2226,21 +2294,25 @@ discard block |
||
| 2226 | 2294 | } |
| 2227 | 2295 | |
| 2228 | 2296 | // *********************************************************************** |
| 2229 | - public function decrypt ($source, $pubkey = NULL){ |
|
| 2297 | + public function decrypt ($source, $pubkey = NULL) |
|
| 2298 | + { |
|
| 2230 | 2299 | // Decryption performed using public key |
| 2231 | - if($pubkey === NULL) |
|
| 2232 | - // Default Key if none is specified |
|
| 2300 | + if($pubkey === NULL) { |
|
| 2301 | + // Default Key if none is specified |
|
| 2233 | 2302 | $pubkey = $this->_ssl_pubkey; |
| 2303 | + } |
|
| 2234 | 2304 | |
| 2235 | - if(!$pubkey) |
|
| 2236 | - // Still no key... |
|
| 2305 | + if(!$pubkey) { |
|
| 2306 | + // Still no key... |
|
| 2237 | 2307 | return false; |
| 2308 | + } |
|
| 2238 | 2309 | |
| 2239 | - if(!function_exists('openssl_get_publickey')) |
|
| 2240 | - return false; |
|
| 2310 | + if(!function_exists('openssl_get_publickey')) { |
|
| 2311 | + return false; |
|
| 2312 | + } |
|
| 2241 | 2313 | |
| 2242 | 2314 | $pkey = openssl_get_publickey($pubkey); |
| 2243 | - if($pkey === false){ |
|
| 2315 | + if($pkey === false) { |
|
| 2244 | 2316 | // bad key |
| 2245 | 2317 | //echo openssl_error_string(); |
| 2246 | 2318 | return false; |
@@ -2249,16 +2321,18 @@ discard block |
||
| 2249 | 2321 | $cryptlist = explode(SpotNab::SSL_BUF_DELIMITER, $source); |
| 2250 | 2322 | |
| 2251 | 2323 | $decrypted = ''; |
| 2252 | - foreach($cryptlist as $crypt){ |
|
| 2253 | - if(!strlen($crypt))break; |
|
| 2324 | + foreach($cryptlist as $crypt) { |
|
| 2325 | + if(!strlen($crypt)) { |
|
| 2326 | + break; |
|
| 2327 | + } |
|
| 2254 | 2328 | $_crypt = base64_decode($crypt); |
| 2255 | - if($_crypt === false){ |
|
| 2329 | + if($_crypt === false) { |
|
| 2256 | 2330 | // Fail |
| 2257 | 2331 | return false; |
| 2258 | 2332 | } |
| 2259 | 2333 | |
| 2260 | 2334 | $res = openssl_public_decrypt($_crypt, $out, $pkey, OPENSSL_PKCS1_PADDING); |
| 2261 | - if($res === false){ |
|
| 2335 | + if($res === false) { |
|
| 2262 | 2336 | // Decryption failed |
| 2263 | 2337 | //echo "DEBUG: ".openssl_error_string()."\n"; |
| 2264 | 2338 | openssl_free_key($pkey); |
@@ -2272,7 +2346,8 @@ discard block |
||
| 2272 | 2346 | } |
| 2273 | 2347 | |
| 2274 | 2348 | // *********************************************************************** |
| 2275 | - public function compstr ($str){ |
|
| 2349 | + public function compstr ($str) |
|
| 2350 | + { |
|
| 2276 | 2351 | /* |
| 2277 | 2352 | * Compress a string |
| 2278 | 2353 | */ |
@@ -2281,7 +2356,8 @@ discard block |
||
| 2281 | 2356 | } |
| 2282 | 2357 | |
| 2283 | 2358 | // *********************************************************************** |
| 2284 | - public function decompstr ($str){ |
|
| 2359 | + public function decompstr ($str) |
|
| 2360 | + { |
|
| 2285 | 2361 | /* |
| 2286 | 2362 | * De-compress a string |
| 2287 | 2363 | */ |
@@ -2342,6 +2418,7 @@ discard block |
||
| 2342 | 2418 | } |
| 2343 | 2419 | |
| 2344 | 2420 | // Create a NNTP \Exception type so we can identify it from others |
| 2345 | -class SpotNabException extends \Exception { |
|
| 2421 | +class SpotNabException extends \Exception |
|
| 2422 | +{ |
|
| 2346 | 2423 | |
| 2347 | 2424 | } |
@@ -258,21 +258,25 @@ discard block |
||
| 258 | 258 | $userName = trim($userName); |
| 259 | 259 | $email = trim($email); |
| 260 | 260 | |
| 261 | - if (!$this->isValidUsername($userName)) |
|
| 262 | - return Users::ERR_SIGNUP_BADUNAME; |
|
| 261 | + if (!$this->isValidUsername($userName)) { |
|
| 262 | + return Users::ERR_SIGNUP_BADUNAME; |
|
| 263 | + } |
|
| 263 | 264 | |
| 264 | - if (!$this->isValidEmail($email)) |
|
| 265 | - return Users::ERR_SIGNUP_BADEMAIL; |
|
| 265 | + if (!$this->isValidEmail($email)) { |
|
| 266 | + return Users::ERR_SIGNUP_BADEMAIL; |
|
| 267 | + } |
|
| 266 | 268 | |
| 267 | 269 | $res = $this->getByUsername($userName); |
| 268 | - if ($res) |
|
| 269 | - if ($res["id"] != $id) |
|
| 270 | + if ($res) { |
|
| 271 | + if ($res["id"] != $id) |
|
| 270 | 272 | return Users::ERR_SIGNUP_UNAMEINUSE; |
| 273 | + } |
|
| 271 | 274 | |
| 272 | 275 | $res = $this->getByEmail($email); |
| 273 | - if ($res) |
|
| 274 | - if ($res["id"] != $id) |
|
| 276 | + if ($res) { |
|
| 277 | + if ($res["id"] != $id) |
|
| 275 | 278 | return Users::ERR_SIGNUP_EMAILINUSE; |
| 279 | + } |
|
| 276 | 280 | |
| 277 | 281 | $sql = []; |
| 278 | 282 | |
@@ -530,23 +534,27 @@ discard block |
||
| 530 | 534 | $password = trim($password); |
| 531 | 535 | $email = trim($email); |
| 532 | 536 | |
| 533 | - if (!$this->isValidUsername($userName)) |
|
| 534 | - return Users::ERR_SIGNUP_BADUNAME; |
|
| 537 | + if (!$this->isValidUsername($userName)) { |
|
| 538 | + return Users::ERR_SIGNUP_BADUNAME; |
|
| 539 | + } |
|
| 535 | 540 | |
| 536 | - if (!$this->isValidPassword($password)) |
|
| 537 | - return Users::ERR_SIGNUP_BADPASS; |
|
| 541 | + if (!$this->isValidPassword($password)) { |
|
| 542 | + return Users::ERR_SIGNUP_BADPASS; |
|
| 543 | + } |
|
| 538 | 544 | |
| 539 | 545 | if (!$this->isValidEmail($email)) { |
| 540 | 546 | return self::ERR_SIGNUP_BADEMAIL; |
| 541 | 547 | } |
| 542 | 548 | |
| 543 | 549 | $res = $this->getByUsername($userName); |
| 544 | - if ($res) |
|
| 545 | - return Users::ERR_SIGNUP_UNAMEINUSE; |
|
| 550 | + if ($res) { |
|
| 551 | + return Users::ERR_SIGNUP_UNAMEINUSE; |
|
| 552 | + } |
|
| 546 | 553 | |
| 547 | 554 | $res = $this->getByEmail($email); |
| 548 | - if ($res) |
|
| 549 | - return Users::ERR_SIGNUP_EMAILINUSE; |
|
| 555 | + if ($res) { |
|
| 556 | + return Users::ERR_SIGNUP_EMAILINUSE; |
|
| 557 | + } |
|
| 550 | 558 | |
| 551 | 559 | // Make sure this is the last check, as if a further validation check failed, the invite would still have been used up. |
| 552 | 560 | $invitedBy = 0; |
@@ -761,8 +769,9 @@ discard block |
||
| 761 | 769 | public function getCart($uid, $releaseid = "") |
| 762 | 770 | { |
| 763 | 771 | |
| 764 | - if ($releaseid != "") |
|
| 765 | - $releaseid = " AND releases.id = " . $this->pdo->escapeString($releaseid); |
|
| 772 | + if ($releaseid != "") { |
|
| 773 | + $releaseid = " AND releases.id = " . $this->pdo->escapeString($releaseid); |
|
| 774 | + } |
|
| 766 | 775 | |
| 767 | 776 | return $this->pdo->query(sprintf("SELECT users_releases.*, releases.searchname,releases.guid FROM users_releases INNER JOIN releases on releases.id = users_releases.releases_id WHERE users_id = %d %s", $uid, $releaseid)); |
| 768 | 777 | } |
@@ -791,8 +800,9 @@ discard block |
||
| 791 | 800 | public function delCartByUserAndRelease($guid, $uid) |
| 792 | 801 | { |
| 793 | 802 | $rel = $this->pdo->queryOneRow(sprintf("SELECT id FROM releases WHERE guid = %s", $this->pdo->escapeString($guid))); |
| 794 | - if ($rel) |
|
| 795 | - $this->pdo->queryExec(sprintf("DELETE FROM users_releases WHERE users_id = %d AND releases_id = %d", $uid, $rel["id"])); |
|
| 803 | + if ($rel) { |
|
| 804 | + $this->pdo->queryExec(sprintf("DELETE FROM users_releases WHERE users_id = %d AND releases_id = %d", $uid, $rel["id"])); |
|
| 805 | + } |
|
| 796 | 806 | } |
| 797 | 807 | |
| 798 | 808 | public function delCartForRelease($rid) |
@@ -814,8 +824,9 @@ discard block |
||
| 814 | 824 | { |
| 815 | 825 | $ret = []; |
| 816 | 826 | $data = $this->pdo->query(sprintf("SELECT categories_id FROM roleexcat WHERE role = %d", $role)); |
| 817 | - foreach ($data as $d) |
|
| 818 | - $ret[] = $d["categories_id"]; |
|
| 827 | + foreach ($data as $d) { |
|
| 828 | + $ret[] = $d["categories_id"]; |
|
| 829 | + } |
|
| 819 | 830 | |
| 820 | 831 | return $ret; |
| 821 | 832 | } |
@@ -1025,8 +1036,9 @@ discard block |
||
| 1025 | 1036 | $res = $this->pdo->query(sprintf("SELECT id FROM users WHERE role = %d", $id)); |
| 1026 | 1037 | if (sizeof($res) > 0) { |
| 1027 | 1038 | $userids = []; |
| 1028 | - foreach ($res as $user) |
|
| 1029 | - $userids[] = $user['id']; |
|
| 1039 | + foreach ($res as $user) { |
|
| 1040 | + $userids[] = $user['id']; |
|
| 1041 | + } |
|
| 1030 | 1042 | $defaultrole = $this->getDefaultRole(); |
| 1031 | 1043 | $this->pdo->queryExec(sprintf("UPDATE users SET role=%d WHERE id IN (%s)", $defaultrole['id'], implode(',', $userids))); |
| 1032 | 1044 | } |
@@ -1187,7 +1199,8 @@ discard block |
||
| 1187 | 1199 | * @param string|int $user |
| 1188 | 1200 | * @return bool |
| 1189 | 1201 | */ |
| 1190 | - public function roleCheck($roleID, $user) { |
|
| 1202 | + public function roleCheck($roleID, $user) |
|
| 1203 | + { |
|
| 1191 | 1204 | |
| 1192 | 1205 | if (is_string($user) && strlen($user) > 0) { |
| 1193 | 1206 | $user = $this->pdo->escapeString($user); |
@@ -1214,7 +1227,8 @@ discard block |
||
| 1214 | 1227 | * @param int $userID |
| 1215 | 1228 | * @return bool |
| 1216 | 1229 | */ |
| 1217 | - public function isAdmin($userID) { |
|
| 1230 | + public function isAdmin($userID) |
|
| 1231 | + { |
|
| 1218 | 1232 | return $this->roleCheck(self::ROLE_ADMIN, (integer) $userID); |
| 1219 | 1233 | } |
| 1220 | 1234 | |
@@ -1224,7 +1238,8 @@ discard block |
||
| 1224 | 1238 | * @param int $userId |
| 1225 | 1239 | * @return bool |
| 1226 | 1240 | */ |
| 1227 | - public function isModerator($userId) { |
|
| 1241 | + public function isModerator($userId) |
|
| 1242 | + { |
|
| 1228 | 1243 | return $this->roleCheck(self::ROLE_MODERATOR, (integer) $userId); |
| 1229 | 1244 | } |
| 1230 | 1245 | } |
@@ -217,9 +217,9 @@ |
||
| 217 | 217 | } |
| 218 | 218 | if ($this->_ret = $this->_html->find("div.screenshot_holder", 0)) { |
| 219 | 219 | if ($this->_ret = $this->_ret->find("a", 0)) { |
| 220 | - if(preg_match('/\?url\=(?<imgurl>.*)/', $this->_ret->href, $matches)){ |
|
| 220 | + if(preg_match('/\?url\=(?<imgurl>.*)/', $this->_ret->href, $matches)) { |
|
| 221 | 221 | $this->_res['backdrop'] = trim($matches['imgurl']); |
| 222 | - }else{ |
|
| 222 | + } else { |
|
| 223 | 223 | $this->_res['backdrop'] = trim($this->_ret->href); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -7,7 +7,8 @@ |
||
| 7 | 7 | * Class TraktAPI |
| 8 | 8 | * Retrive info from the Trakt API. |
| 9 | 9 | */ |
| 10 | -Class TraktAPI { |
|
| 10 | +Class TraktAPI |
|
| 11 | +{ |
|
| 11 | 12 | |
| 12 | 13 | const API_URL = 'https://api-v2launch.trakt.tv/'; |
| 13 | 14 | |
@@ -219,7 +219,8 @@ discard block |
||
| 219 | 219 | { |
| 220 | 220 | $gzipped = null; |
| 221 | 221 | if (($fp = fopen($filename, 'r')) !== false) { |
| 222 | - if (@fread($fp, 2) == "\x1F\x8B") { // this is a gzip'd file |
|
| 222 | + if (@fread($fp, 2) == "\x1F\x8B") { |
|
| 223 | +// this is a gzip'd file |
|
| 223 | 224 | fseek($fp, -4, SEEK_END); |
| 224 | 225 | if (strlen($datum = @fread($fp, 4)) == 4) { |
| 225 | 226 | $gzipped = $datum; |
@@ -576,7 +577,8 @@ discard block |
||
| 576 | 577 | * |
| 577 | 578 | * @return array The associate array of the XML namespaced file |
| 578 | 579 | */ |
| 579 | - public static function xmlToArray(\SimpleXMLElement $xml, $options = []) { |
|
| 580 | + public static function xmlToArray(\SimpleXMLElement $xml, $options = []) |
|
| 581 | + { |
|
| 580 | 582 | $defaults = array( |
| 581 | 583 | 'namespaceSeparator' => ':',//you may want this to be something other than a colon |
| 582 | 584 | 'attributePrefix' => '@', //to distinguish between attributes and nodes with the same name |
@@ -596,8 +598,10 @@ discard block |
||
| 596 | 598 | //get attributes from all namespaces |
| 597 | 599 | foreach ($xml->attributes($namespace) as $attributeName => $attribute) { |
| 598 | 600 | //replace characters in attribute name |
| 599 | - if ($options['keySearch']) $attributeName = |
|
| 601 | + if ($options['keySearch']) { |
|
| 602 | + $attributeName = |
|
| 600 | 603 | str_replace($options['keySearch'], $options['keyReplace'], $attributeName); |
| 604 | + } |
|
| 601 | 605 | $attributeKey = $options['attributePrefix'] |
| 602 | 606 | . ($prefix ? $prefix . $options['namespaceSeparator'] : '') |
| 603 | 607 | . $attributeName; |
@@ -610,10 +614,14 @@ discard block |
||
| 610 | 614 | list($childTagName, $childProperties) = each($childArray); |
| 611 | 615 | |
| 612 | 616 | //replace characters in tag name |
| 613 | - if ($options['keySearch']) $childTagName = |
|
| 617 | + if ($options['keySearch']) { |
|
| 618 | + $childTagName = |
|
| 614 | 619 | str_replace($options['keySearch'], $options['keyReplace'], $childTagName); |
| 620 | + } |
|
| 615 | 621 | //add namespace prefix, if any |
| 616 | - if ($prefix) $childTagName = $prefix . $options['namespaceSeparator'] . $childTagName; |
|
| 622 | + if ($prefix) { |
|
| 623 | + $childTagName = $prefix . $options['namespaceSeparator'] . $childTagName; |
|
| 624 | + } |
|
| 617 | 625 | |
| 618 | 626 | if (!isset($tagsArray[$childTagName])) { |
| 619 | 627 | //only entry with this key |
@@ -637,7 +645,9 @@ discard block |
||
| 637 | 645 | //get text content of node |
| 638 | 646 | $textContentArray = []; |
| 639 | 647 | $plainText = trim((string)$xml); |
| 640 | - if ($plainText !== '') $textContentArray[$options['textContent']] = $plainText; |
|
| 648 | + if ($plainText !== '') { |
|
| 649 | + $textContentArray[$options['textContent']] = $plainText; |
|
| 650 | + } |
|
| 641 | 651 | |
| 642 | 652 | //stick it all together |
| 643 | 653 | $propertiesArray = !$options['autoText'] || $attributesArray || $tagsArray || ($plainText === '') |
@@ -971,7 +981,8 @@ discard block |
||
| 971 | 981 | * |
| 972 | 982 | * @return int $e |
| 973 | 983 | */ |
| 974 | - public static function convertRomanToInt($string) { |
|
| 984 | + public static function convertRomanToInt($string) |
|
| 985 | + { |
|
| 975 | 986 | switch (strtolower($string)) { |
| 976 | 987 | case 'i': $e = 1; |
| 977 | 988 | break; |