@@ -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 | } |
@@ -1026,8 +1026,8 @@ |
||
| 1026 | 1026 | |
| 1027 | 1027 | public function isXxxClipSD() |
| 1028 | 1028 | { |
| 1029 | - switch(true) { |
|
| 1030 | - case $this->checkPoster( '/oz@lot[.]com/i', $this->poster, Category::XXX_CLIPSD): |
|
| 1029 | + switch (true) { |
|
| 1030 | + case $this->checkPoster('/oz@lot[.]com/i', $this->poster, Category::XXX_CLIPSD): |
|
| 1031 | 1031 | return true; |
| 1032 | 1032 | case preg_match('/SDPORN/i', $this->releaseName): |
| 1033 | 1033 | $this->tmpCat = Category::XXX_CLIPSD; |
@@ -106,8 +106,8 @@ |
||
| 106 | 106 | public function __construct(array $options = []) |
| 107 | 107 | { |
| 108 | 108 | $defaults = [ |
| 109 | - 'Browser' => false, // Was this started from the browser? |
|
| 110 | - 'Echo' => true, // Echo to CLI? |
|
| 109 | + 'Browser' => false, // Was this started from the browser? |
|
| 110 | + 'Echo' => true, // Echo to CLI? |
|
| 111 | 111 | 'Binaries' => null, |
| 112 | 112 | 'Categorize' => null, |
| 113 | 113 | 'NZB' => null, |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $this->rsstoken = $page->userdata['rsstoken']; |
| 89 | 89 | |
| 90 | 90 | if (!empty($page->userdata['nzbgeturl'])) { |
| 91 | - $this->url = $page->userdata['nzbgeturl']; |
|
| 91 | + $this->url = $page->userdata['nzbgeturl']; |
|
| 92 | 92 | $this->userName = (empty($page->userdata['nzbgetusername']) ? '' : $page->userdata['nzbgetusername']); |
| 93 | 93 | $this->password = (empty($page->userdata['nzbgetpassword']) ? '' : $page->userdata['nzbgetpassword']); |
| 94 | 94 | } |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | if ($xml) { |
| 382 | 382 | $retVal = []; |
| 383 | 383 | $i = 0; |
| 384 | - foreach($xml->params->param->value->array->data->value as $value) { |
|
| 384 | + foreach ($xml->params->param->value->array->data->value as $value) { |
|
| 385 | 385 | foreach ($value->struct->member as $member) { |
| 386 | 386 | $value = (array)$member->value; |
| 387 | 387 | $value = array_shift($value); |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | if ($data) { |
| 411 | 411 | $xml = simplexml_load_string($data); |
| 412 | 412 | if ($xml) { |
| 413 | - foreach($xml->params->param->value->struct->member as $member) { |
|
| 413 | + foreach ($xml->params->param->value->struct->member as $member) { |
|
| 414 | 414 | $value = (array)$member->value; |
| 415 | 415 | $value = array_shift($value); |
| 416 | 416 | if (!is_object($value)) { |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * |
| 433 | 433 | * @access public |
| 434 | 434 | */ |
| 435 | - public function verifyURL ($url) |
|
| 435 | + public function verifyURL($url) |
|
| 436 | 436 | { |
| 437 | 437 | if (preg_match('/(?P<protocol>https?):\/\/(?P<url>.+?)(:(?P<port>\d+\/)|\/)$/i', $url, $matches)) { |
| 438 | 438 | return |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public function showMemUsage($oldUsage = 0, $realUsage = false, $peak = false) |
| 268 | 268 | { |
| 269 | - $currentUsage = ($peak ? memory_get_peak_usage($realUsage) : memory_get_usage($realUsage)); |
|
| 269 | + $currentUsage = ($peak ? memory_get_peak_usage($realUsage) : memory_get_usage($realUsage)); |
|
| 270 | 270 | $actualUsage = ($oldUsage > 0 ? $currentUsage - $oldUsage : $currentUsage); |
| 271 | 271 | |
| 272 | 272 | $units = [ |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $usage = getrusage(); |
| 314 | 314 | |
| 315 | 315 | return |
| 316 | - 'USR: ' . $this->formatTimeString($usage['ru_utime.tv_sec']) . |
|
| 316 | + 'USR: ' . $this->formatTimeString($usage['ru_utime.tv_sec']) . |
|
| 317 | 317 | ' SYS: ' . $this->formatTimeString($usage['ru_stime.tv_sec']) . |
| 318 | 318 | ' FAULTS: ' . $usage['ru_majflt'] . |
| 319 | 319 | ' SWAPS: ' . $usage['ru_nswap']; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | if (!$this->isWindows) { |
| 334 | 334 | $string = ''; |
| 335 | 335 | // Fix for single digits (2) or single float (2.1). |
| 336 | - foreach(sys_getloadavg() as $load) { |
|
| 336 | + foreach (sys_getloadavg() as $load) { |
|
| 337 | 337 | $strLen = strlen($load); |
| 338 | 338 | if ($strLen === 1) { |
| 339 | 339 | $string .= $load . '.00,'; |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | asort($logs); |
| 605 | 605 | |
| 606 | 606 | // Remove all new logs from array (all elements under the last 51 elements of the array). |
| 607 | - array_splice($logs, -$this->maxLogs+1); |
|
| 607 | + array_splice($logs, -$this->maxLogs + 1); |
|
| 608 | 608 | |
| 609 | 609 | // Delete all the logs left in the array. |
| 610 | 610 | array_map('unlink', $logs); |
@@ -697,11 +697,11 @@ discard block |
||
| 697 | 697 | $time .= '00H:'; |
| 698 | 698 | } |
| 699 | 699 | if ($seconds > 60) { |
| 700 | - $time .= str_pad(round((($seconds % 3600) / 60)), 2 , '0', STR_PAD_LEFT) . 'M:'; |
|
| 700 | + $time .= str_pad(round((($seconds % 3600) / 60)), 2, '0', STR_PAD_LEFT) . 'M:'; |
|
| 701 | 701 | } else { |
| 702 | 702 | $time .= '00M:'; |
| 703 | 703 | } |
| 704 | - $time .= str_pad($seconds % 60, 2 , '0', STR_PAD_LEFT) . 'S'; |
|
| 704 | + $time .= str_pad($seconds % 60, 2, '0', STR_PAD_LEFT) . 'S'; |
|
| 705 | 705 | return $time; |
| 706 | 706 | } |
| 707 | 707 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Settings key literals |
| 62 | 62 | */ |
| 63 | - const RECAPTCHA_SETTING_SITEKEY = 'recaptchapublickey'; |
|
| 64 | - const RECAPTCHA_SETTING_SECRETKEY = 'recaptchaprivatekey'; |
|
| 63 | + const RECAPTCHA_SETTING_SITEKEY = 'recaptchapublickey'; |
|
| 64 | + const RECAPTCHA_SETTING_SECRETKEY = 'recaptchaprivatekey'; |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Construct and decide whether to show the captcha or not. |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $rc_error = 'ReCaptcha Failed: '; |
| 151 | 151 | |
| 152 | 152 | foreach ($codes as $c) { |
| 153 | - switch($c) { |
|
| 153 | + switch ($c) { |
|
| 154 | 154 | case self::RECAPTCHA_ERROR_MISSING_SECRET: |
| 155 | 155 | $rc_error .= 'Missing Secret Key'; |
| 156 | 156 | break; |
@@ -1213,7 +1213,7 @@ |
||
| 1213 | 1213 | $aMin = $data['first']; |
| 1214 | 1214 | $reallyOldArticle = $oldArticle = $articleTime = null; |
| 1215 | 1215 | |
| 1216 | - while(true) { |
|
| 1216 | + while (true) { |
|
| 1217 | 1217 | // Article exists outside of available range, this shouldn't happen |
| 1218 | 1218 | if ($wantedArticle <= $data['first'] || $wantedArticle >= $data['last']) { |
| 1219 | 1219 | break; |
@@ -64,8 +64,8 @@ |
||
| 64 | 64 | |
| 65 | 65 | const NFO_FAILED = -9; // We failed to get a NFO after admin set max retries. |
| 66 | 66 | const NFO_UNPROC = -1; // Release has not been processed yet. |
| 67 | - const NFO_NONFO = 0; // Release has no NFO. |
|
| 68 | - const NFO_FOUND = 1; // Release has an NFO. |
|
| 67 | + const NFO_NONFO = 0; // Release has no NFO. |
|
| 68 | + const NFO_FOUND = 1; // Release has an NFO. |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Default constructor. |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use app\extensions\util\Yenc; |
| 7 | 7 | |
| 8 | 8 | // Help out those who don't have SSL enabled |
| 9 | -if(!defined('OPENSSL_KEYTYPE_RSA')) { |
|
| 9 | +if (!defined('OPENSSL_KEYTYPE_RSA')) { |
|
| 10 | 10 | // OPENSSL_KEYTYPE_RSA is defined as 0 in php v4 and v5 |
| 11 | 11 | // so just give it a value to silence possible Notice Errors |
| 12 | 12 | // for Windows Users (and give it the correct value) |
@@ -17,11 +17,11 @@ 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')) 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); |
|
| 25 | 25 | |
| 26 | 26 | class SpotNab { |
| 27 | 27 | // Segment Identifier domain is used to help build segments |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | public function __construct($post_user = NULL, $post_email = NULL, $post_group = NULL) { |
| 138 | 138 | $this->_pdo = new Settings(); |
| 139 | 139 | $this->_nntp = new NNTP(['Settings' => $this->_pdo]); |
| 140 | - $this->releaseImage = new ReleaseImage($this->_pdo); |
|
| 140 | + $this->releaseImage = new ReleaseImage($this->_pdo); |
|
| 141 | 141 | $this->nzb = new NZB($this->_pdo); |
| 142 | 142 | $this->releases = new Releases(['Settings' => $this->_pdo]); |
| 143 | 143 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | $this->_post_group = $post_group; |
| 147 | 147 | |
| 148 | 148 | // Fetch Meta information |
| 149 | - $this->_post_code = trim($this->_pdo->getSetting('code'))? |
|
| 150 | - $this->_pdo->getSetting('code'):NULL; |
|
| 151 | - $this->_post_title = trim($this->_pdo->getSetting('title'))? |
|
| 152 | - $this->_pdo->getSetting('title'):NULL; |
|
| 149 | + $this->_post_code = trim($this->_pdo->getSetting('code')) ? |
|
| 150 | + $this->_pdo->getSetting('code') : NULL; |
|
| 151 | + $this->_post_title = trim($this->_pdo->getSetting('title')) ? |
|
| 152 | + $this->_pdo->getSetting('title') : NULL; |
|
| 153 | 153 | |
| 154 | - if ($this->_post_user === NULL){ |
|
| 154 | + if ($this->_post_user === NULL) { |
|
| 155 | 155 | // Fetch the SpotNab UserID |
| 156 | - $this->_post_user = trim($this->_pdo->getSetting('spotnabuser'))? |
|
| 157 | - $this->_pdo->getSetting('spotnabuser'):NULL; |
|
| 156 | + $this->_post_user = trim($this->_pdo->getSetting('spotnabuser')) ? |
|
| 157 | + $this->_pdo->getSetting('spotnabuser') : NULL; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ($this->_post_email === NULL){ |
|
| 160 | + if ($this->_post_email === NULL) { |
|
| 161 | 161 | // Fetch the SpotNab EmailID |
| 162 | - $this->_post_email = trim($this->_pdo->getSetting('spotnabemail'))? |
|
| 163 | - $this->_pdo->getSetting('spotnabemail'):NULL; |
|
| 162 | + $this->_post_email = trim($this->_pdo->getSetting('spotnabemail')) ? |
|
| 163 | + $this->_pdo->getSetting('spotnabemail') : NULL; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if ($this->_post_group === NULL){ |
|
| 166 | + if ($this->_post_group === NULL) { |
|
| 167 | 167 | // Fetch the SpotNab Usenet Group |
| 168 | - $this->_post_group = trim($this->_pdo->getSetting('spotnabgroup'))? |
|
| 169 | - $this->_pdo->getSetting('spotnabgroup'):NULL; |
|
| 168 | + $this->_post_group = trim($this->_pdo->getSetting('spotnabgroup')) ? |
|
| 169 | + $this->_pdo->getSetting('spotnabgroup') : NULL; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // Public Key |
| 173 | - $this->_ssl_pubkey = trim($this->_pdo->getSetting('spotnabsitepubkey'))? |
|
| 174 | - $this->_pdo->getSetting('spotnabsitepubkey'):false; |
|
| 175 | - if($this->_ssl_pubkey) |
|
| 173 | + $this->_ssl_pubkey = trim($this->_pdo->getSetting('spotnabsitepubkey')) ? |
|
| 174 | + $this->_pdo->getSetting('spotnabsitepubkey') : false; |
|
| 175 | + if ($this->_ssl_pubkey) |
|
| 176 | 176 | $this->_ssl_pubkey = $this->decompstr($this->_ssl_pubkey); |
| 177 | 177 | |
| 178 | 178 | // Private Key |
| 179 | - $this->_ssl_prvkey = trim($this->_pdo->getSetting('spotnabsiteprvkey'))? |
|
| 180 | - $this->_pdo->getSetting('spotnabsiteprvkey'):false; |
|
| 181 | - if($this->_ssl_prvkey) |
|
| 179 | + $this->_ssl_prvkey = trim($this->_pdo->getSetting('spotnabsiteprvkey')) ? |
|
| 180 | + $this->_pdo->getSetting('spotnabsiteprvkey') : false; |
|
| 181 | + if ($this->_ssl_prvkey) |
|
| 182 | 182 | $this->_ssl_prvkey = $this->decompstr($this->_ssl_prvkey); |
| 183 | 183 | |
| 184 | 184 | // Track Discovery Article |
| 185 | 185 | $this->_discovery_lastarticle = intval($this->_pdo->getSetting('spotnablastarticle')); |
| 186 | 186 | |
| 187 | 187 | // Posting Flag |
| 188 | - $this->_can_post = (trim($this->_pdo->getSetting('spotnabpost')) == 1)? |
|
| 189 | - true:false; |
|
| 188 | + $this->_can_post = (trim($this->_pdo->getSetting('spotnabpost')) == 1) ? |
|
| 189 | + true : false; |
|
| 190 | 190 | |
| 191 | 191 | // Auto Enable Flag |
| 192 | - $this->_auto_enable = (trim($this->_pdo->getSetting('spotnabautoenable')) == 1)? |
|
| 193 | - true:false; |
|
| 192 | + $this->_auto_enable = (trim($this->_pdo->getSetting('spotnabautoenable')) == 1) ? |
|
| 193 | + true : false; |
|
| 194 | 194 | |
| 195 | 195 | // Spotnab Privacy Posting |
| 196 | - $this->_post_privacy = (trim($this->_pdo->getSetting('spotnabprivacy')) == 1)? |
|
| 197 | - true:false; |
|
| 196 | + $this->_post_privacy = (trim($this->_pdo->getSetting('spotnabprivacy')) == 1) ? |
|
| 197 | + true : false; |
|
| 198 | 198 | |
| 199 | 199 | // Auto-Discovery Private Key (used for Posting) |
| 200 | 200 | $this->_ssl_auto_prvkey = "eJxtk7mOo0AARHO+YnI0Moe5woYGppv7PjLABmzAgDFg" |
@@ -222,14 +222,14 @@ discard block |
||
| 222 | 222 | ."LVDl"; |
| 223 | 223 | |
| 224 | 224 | // Auto-Discovery Flags |
| 225 | - $this->_can_broadcast = (trim($this->_pdo->getSetting('spotnabbroadcast')) == 1)? |
|
| 226 | - true:false; |
|
| 225 | + $this->_can_broadcast = (trim($this->_pdo->getSetting('spotnabbroadcast')) == 1) ? |
|
| 226 | + true : false; |
|
| 227 | 227 | $this->_can_broadcast = ($this->_can_broadcast && $this->_can_post); |
| 228 | 228 | |
| 229 | - $this->_can_discover = (trim($this->_pdo->getSetting('spotnabdiscover')) == 1)? |
|
| 230 | - true:false; |
|
| 229 | + $this->_can_discover = (trim($this->_pdo->getSetting('spotnabdiscover')) == 1) ? |
|
| 230 | + true : false; |
|
| 231 | 231 | |
| 232 | - if (!$this->has_openssl()){ |
|
| 232 | + if (!$this->has_openssl()) { |
|
| 233 | 233 | // Can SpotNab even work; if not, we disable all flags |
| 234 | 234 | $this->_can_broadcast = false; |
| 235 | 235 | $this->_can_post = false; |
@@ -237,14 +237,14 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // *********************************************************************** |
| 240 | - public function has_openssl(){ |
|
| 240 | + public function has_openssl() { |
|
| 241 | 241 | // return true if ssl is correctly configured and installed |
| 242 | 242 | // otherwise return a fail |
| 243 | 243 | return (is_readable(OPENSSL_CFG_PATH) && extension_loaded("openssl")); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // *********************************************************************** |
| 247 | - public function auto_clean($max_days=90){ |
|
| 247 | + public function auto_clean($max_days = 90) { |
|
| 248 | 248 | // automatically sweep old sources lingering that have not shown any |
| 249 | 249 | // sort of life what-so-ever for more then 90 days |
| 250 | 250 | $sql = "DELETE FROM spotnabsources WHERE " |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // *********************************************************************** |
| 257 | - public function orphan_comment_clean($max_days=1, $batch=500) |
|
| 257 | + public function orphan_comment_clean($max_days = 1, $batch = 500) |
|
| 258 | 258 | { |
| 259 | 259 | // Clean out orphan comments that are older then at least 1 day |
| 260 | 260 | // this is to address people who do not wish to hold on to |
@@ -269,29 +269,29 @@ discard block |
||
| 269 | 269 | $sql_rel = "SELECT gid FROM releases WHERE gid IN ('%s') "; |
| 270 | 270 | $sql_del = "DELETE FROM release_comments WHERE gid IN ('%s')"; |
| 271 | 271 | $total_delcnt = 0; |
| 272 | - while(1) { |
|
| 272 | + while (1) { |
|
| 273 | 273 | $res = $this->_pdo->query(sprintf($sql, $offset, $batch)); |
| 274 | - if(!$res) { |
|
| 274 | + if (!$res) { |
|
| 275 | 275 | break; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | # Assemble results into list |
| 279 | 279 | $gids_found = []; |
| 280 | 280 | $gids_matched = []; |
| 281 | - foreach($res as $item) { |
|
| 281 | + foreach ($res as $item) { |
|
| 282 | 282 | $gids_found[] = $item['gid']; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | #echo 'B:'.sprintf($sql_rel, implode("','", $gids_found))."\n"; |
| 286 | 286 | $res2 = $this->_pdo->query(sprintf($sql_rel, implode("','", $gids_found))); |
| 287 | - foreach($res2 as $item) { |
|
| 287 | + foreach ($res2 as $item) { |
|
| 288 | 288 | $gids_matched[] = $item['gid']; |
| 289 | 289 | } |
| 290 | 290 | # Now we want to create an inverted list by eliminating the |
| 291 | 291 | # matches we just fetched |
| 292 | 292 | $gids_missing = array_diff($gids_found, $gids_matched); |
| 293 | 293 | //print_r($gids_missing); |
| 294 | - if(count($gids_missing)) { |
|
| 294 | + if (count($gids_missing)) { |
|
| 295 | 295 | $s_gids_missing = implode("','", $gids_missing); |
| 296 | 296 | $dresc = $this->_pdo->queryExec(sprintf($sql_del, $s_gids_missing)); |
| 297 | 297 | $total_delcnt += count($gids_missing); |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | # make noise |
| 303 | 303 | echo '.'; |
| 304 | 304 | |
| 305 | - if(!count($res)) { |
|
| 305 | + if (!count($res)) { |
|
| 306 | 306 | break; |
| 307 | 307 | } |
| 308 | 308 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // *********************************************************************** |
| 313 | - public function soft_reset(){ |
|
| 313 | + public function soft_reset() { |
|
| 314 | 314 | // A harmless function that resets spotnab without losing sources |
| 315 | 315 | // Calling this function will reset spotnab to think: |
| 316 | 316 | // - it hasn't fetched anything yet from existing sources |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | // Discovery should only be set back X days worth defined |
| 335 | 335 | // by the maximum age a broadcast can be. |
| 336 | 336 | $reftime = date("Y-m-d H:i:s", |
| 337 | - time()-(SpotNab::POST_BROADCAST_INTERVAL)); |
|
| 337 | + time() - (SpotNab::POST_BROADCAST_INTERVAL)); |
|
| 338 | 338 | $discovery_b = "Update settings SET " |
| 339 | 339 | ."updateddate = '1980-01-01 00:00:00' " |
| 340 | 340 | ."WHERE setting = 'spotnabdiscover'"; |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | // *********************************************************************** |
| 353 | - public function fetch_discovery($reftime = NULL, $retries=3){ |
|
| 353 | + public function fetch_discovery($reftime = NULL, $retries = 3) { |
|
| 354 | 354 | $last = $first = NULL; |
| 355 | 355 | |
| 356 | 356 | // Return Value; Initialize it to Okay |
@@ -361,31 +361,31 @@ discard block |
||
| 361 | 361 | $inserted = 0; |
| 362 | 362 | $updated = 0; |
| 363 | 363 | |
| 364 | - if (!$this->_can_discover){ |
|
| 364 | + if (!$this->_can_discover) { |
|
| 365 | 365 | // discovery disabled |
| 366 | 366 | return false; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if($reftime === NULL){ |
|
| 369 | + if ($reftime === NULL) { |
|
| 370 | 370 | $q = "SELECT updateddate FROM settings WHERE " |
| 371 | 371 | ."setting = 'spotnabdiscover'"; |
| 372 | 372 | $res = $this->_pdo->queryOneRow($q); |
| 373 | - if($res){ |
|
| 373 | + if ($res) { |
|
| 374 | 374 | $reftime = $res['updateddate']; |
| 375 | - }else{ |
|
| 375 | + } else { |
|
| 376 | 376 | // Fetch local time (but look back the maximum duration |
| 377 | 377 | // that a discovery message can exist for |
| 378 | - $reftime = $this->utc2local((time()-(SpotNab::POST_BROADCAST_INTERVAL))); |
|
| 378 | + $reftime = $this->utc2local((time() - (SpotNab::POST_BROADCAST_INTERVAL))); |
|
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | // Connect to server |
| 383 | - try{ |
|
| 383 | + try { |
|
| 384 | 384 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 385 | 385 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | - catch(\Exception $e){ |
|
| 388 | + catch (\Exception $e) { |
|
| 389 | 389 | printf("Failed to connect to Usenet\n"); |
| 390 | 390 | return false; |
| 391 | 391 | } |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | SpotNab::AUTODISCOVER_POST_GROUP); |
| 396 | 396 | |
| 397 | 397 | $first = $this->_discovery_lastarticle; |
| 398 | - if($first <= 0 || $first > $summary['last'] ){ |
|
| 398 | + if ($first <= 0 || $first > $summary['last']) { |
|
| 399 | 399 | // Look back until reftime |
| 400 | 400 | $first = $this->_first_article_by_date( |
| 401 | 401 | SpotNab::AUTODISCOVER_POST_GROUP, |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | ); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - if($first === false){ |
|
| 406 | + if ($first === false) { |
|
| 407 | 407 | // Fail |
| 408 | 408 | echo "Failed\n"; |
| 409 | 409 | return false; |
@@ -412,10 +412,10 @@ discard block |
||
| 412 | 412 | // Group Processing Initialization |
| 413 | 413 | $processed = 0; |
| 414 | 414 | $batch = $last = intval($summary['last']); |
| 415 | - $total = abs($last-$first); |
|
| 415 | + $total = abs($last - $first); |
|
| 416 | 416 | |
| 417 | 417 | // Select Group |
| 418 | - while($fetch_okay && $processed < $total) |
|
| 418 | + while ($fetch_okay && $processed < $total) |
|
| 419 | 419 | { |
| 420 | 420 | try |
| 421 | 421 | { |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | $headers = $this->_get_headers(SpotNab::AUTODISCOVER_POST_GROUP, |
| 430 | 430 | "$first-$batch", $retries); |
| 431 | 431 | |
| 432 | - if($headers === false){ |
|
| 432 | + if ($headers === false) { |
|
| 433 | 433 | // Retry Atempts exausted |
| 434 | 434 | $fetch_okay = false; |
| 435 | 435 | break; |
@@ -437,33 +437,33 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | // Process the header batch |
| 439 | 439 | $saved = $this->process_discovery_headers($headers); |
| 440 | - if($saved !== false) |
|
| 440 | + if ($saved !== false) |
|
| 441 | 441 | { |
| 442 | 442 | $inserted += $saved[0]; |
| 443 | 443 | $updated += $saved[1]; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - $processed += ($batch-$first); |
|
| 446 | + $processed += ($batch - $first); |
|
| 447 | 447 | // Increment starting index |
| 448 | - $first += ($batch-$first); |
|
| 448 | + $first += ($batch - $first); |
|
| 449 | 449 | |
| 450 | - if ($last-$first >= SpotNab::FETCH_USENET_BATCH){ |
|
| 450 | + if ($last - $first >= SpotNab::FETCH_USENET_BATCH) { |
|
| 451 | 451 | // Fetch next batch |
| 452 | 452 | $batch = $first + SpotNab::FETCH_USENET_BATCH; |
| 453 | - }else{ |
|
| 453 | + } else { |
|
| 454 | 454 | $batch = $last; |
| 455 | 455 | } |
| 456 | 456 | //echo "$first-$batch, processed=$processed\n"; |
| 457 | 457 | //print_r($headers); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - }catch(\Exception $e){ |
|
| 460 | + } catch (\Exception $e) { |
|
| 461 | 461 | // Reset Connection |
| 462 | 462 | $fetch_okay = $this->_nntpReset(SpotNab::AUTODISCOVER_POST_GROUP); |
| 463 | 463 | |
| 464 | 464 | // Track retry attempts |
| 465 | 465 | $retries--; |
| 466 | - if($retries <= 0){ |
|
| 466 | + if ($retries <= 0) { |
|
| 467 | 467 | // Retry Atempts exausted |
| 468 | 468 | $fetch_okay = false; |
| 469 | 469 | break; |
@@ -485,16 +485,16 @@ discard block |
||
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // *********************************************************************** |
| 488 | - public function auto_post_discovery($repost_sec = SpotNab::POST_BROADCAST_INTERVAL){ |
|
| 488 | + public function auto_post_discovery($repost_sec = SpotNab::POST_BROADCAST_INTERVAL) { |
|
| 489 | 489 | // performs a post discovery once the time in seconds has elapsed |
| 490 | 490 | $q = "SELECT updateddate FROM settings WHERE " |
| 491 | 491 | ."setting = 'spotnabbroadcast'"; |
| 492 | 492 | $res = $this->_pdo->queryOneRow($q); |
| 493 | 493 | $then = strtotime($res['updateddate']); |
| 494 | 494 | $now = time(); |
| 495 | - if(($now - $then) > $repost_sec){ |
|
| 495 | + if (($now - $then) > $repost_sec) { |
|
| 496 | 496 | // perform a post |
| 497 | - if($this->post_discovery()) |
|
| 497 | + if ($this->post_discovery()) |
|
| 498 | 498 | { |
| 499 | 499 | // Update post time |
| 500 | 500 | $q = "Update settings SET updateddate = NOW() WHERE " |
@@ -505,30 +505,30 @@ discard block |
||
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // *********************************************************************** |
| 508 | - public function post_discovery($reftime = NULL, $retries=3){ |
|
| 508 | + public function post_discovery($reftime = NULL, $retries = 3) { |
|
| 509 | 509 | $reftime_local = $reftime; |
| 510 | 510 | $article = NULL; |
| 511 | 511 | $rc = new ReleaseComments(); |
| 512 | 512 | $us = new Users(); |
| 513 | 513 | |
| 514 | - if($reftime_local === NULL){ |
|
| 514 | + if ($reftime_local === NULL) { |
|
| 515 | 515 | // Fetch local time |
| 516 | 516 | $reftime_local = $this->utc2local(); |
| 517 | 517 | } |
| 518 | 518 | // some error checking.... |
| 519 | - if(!$this->_can_broadcast){ |
|
| 519 | + if (!$this->_can_broadcast) { |
|
| 520 | 520 | // Broadcasting not possible |
| 521 | 521 | return false; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | // Generate keys if one doesn't exist |
| 525 | - if(!($this->_ssl_prvkey && $this->_ssl_pubkey)) |
|
| 526 | - if($this->keygen(false, true) === false) |
|
| 525 | + if (!($this->_ssl_prvkey && $this->_ssl_pubkey)) |
|
| 526 | + if ($this->keygen(false, true) === false) |
|
| 527 | 527 | return false; |
| 528 | 528 | |
| 529 | 529 | // Get Discovery Private Key |
| 530 | 530 | $prvkey = $this->decompstr($this->_ssl_auto_prvkey); |
| 531 | - if (!$prvkey){ |
|
| 531 | + if (!$prvkey) { |
|
| 532 | 532 | // This is a serious problem because the hard-coded discovery |
| 533 | 533 | // key should always decrypt! |
| 534 | 534 | return false; |
@@ -537,9 +537,9 @@ discard block |
||
| 537 | 537 | printf("Spotnab : Broadcast ..."); |
| 538 | 538 | |
| 539 | 539 | // Fetch some date ranges |
| 540 | - $last_month = date("Y-m-d",strtotime( |
|
| 540 | + $last_month = date("Y-m-d", strtotime( |
|
| 541 | 541 | date("Y-m-d", time()) . " - 30 day")); |
| 542 | - $last_year = date('Y-m-d',strtotime( |
|
| 542 | + $last_year = date('Y-m-d', strtotime( |
|
| 543 | 543 | date("Y-m-d", time()) . " - 365 day")); |
| 544 | 544 | |
| 545 | 545 | // Header |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | SpotNab::AUTODISCOVER_POST_GROUP |
| 577 | 577 | ); |
| 578 | 578 | |
| 579 | - if($article === false){ |
|
| 579 | + if ($article === false) { |
|
| 580 | 580 | echo "Failed.\n"; |
| 581 | 581 | return false; |
| 582 | 582 | } |
@@ -615,16 +615,16 @@ discard block |
||
| 615 | 615 | |
| 616 | 616 | // We set a cap on how many days in the past we look |
| 617 | 617 | $_max_age = time() - SpotNab::FETCH_MAXIMUM_AGE; |
| 618 | - if($reftime === NULL){ |
|
| 618 | + if ($reftime === NULL) { |
|
| 619 | 619 | // Fetch local time (but look back X days) |
| 620 | 620 | $reftime = $this->utc2local($_max_age); |
| 621 | - }else{ |
|
| 621 | + } else { |
|
| 622 | 622 | // Someone specified a date range to query from |
| 623 | 623 | $backfill = true; |
| 624 | 624 | |
| 625 | - if(is_string($reftime)){ |
|
| 625 | + if (is_string($reftime)) { |
|
| 626 | 626 | $reftime = date("Y-m-d H:i:s", strtotime($reftime)); |
| 627 | - }else if(is_int($reftime)){ |
|
| 627 | + } else if (is_int($reftime)) { |
|
| 628 | 628 | $reftime = date("Y-m-d H:i:s", $reftime); |
| 629 | 629 | } |
| 630 | 630 | $_max_age = strtotime($reftime); |
@@ -637,12 +637,12 @@ discard block |
||
| 637 | 637 | $group_article_start = []; |
| 638 | 638 | $id_hash = []; |
| 639 | 639 | |
| 640 | - if(!count($res)) |
|
| 640 | + if (!count($res)) |
|
| 641 | 641 | return true; |
| 642 | 642 | |
| 643 | - foreach($res as $source){ |
|
| 643 | + foreach ($res as $source) { |
|
| 644 | 644 | $ghash = trim($source['usenetgroup']); |
| 645 | - if(!array_key_exists($ghash, $group_hash)){ |
|
| 645 | + if (!array_key_exists($ghash, $group_hash)) { |
|
| 646 | 646 | // Because our results are sorted by group, if we enter |
| 647 | 647 | // here then we're processing a brand new group... |
| 648 | 648 | $group_hash[$ghash] = []; |
@@ -662,9 +662,9 @@ discard block |
||
| 662 | 662 | |
| 663 | 663 | // Therefore, we need to take the lastupdate time and convert it to |
| 664 | 664 | // UTC for processing. |
| 665 | - $ref = $backfill?date("Y-m-d H:i:s", $_max_age):$source['lastupdate']; |
|
| 665 | + $ref = $backfill ? date("Y-m-d H:i:s", $_max_age) : $source['lastupdate']; |
|
| 666 | 666 | |
| 667 | - if(!$ref){ |
|
| 667 | + if (!$ref) { |
|
| 668 | 668 | // We've never fetched from the group before, so we'll use |
| 669 | 669 | // the reftime passed to the function |
| 670 | 670 | $ref = $reftime; |
@@ -673,12 +673,12 @@ discard block |
||
| 673 | 673 | // Therefore, we need to take the lastupdate time and convert it to |
| 674 | 674 | // UTC for processing. |
| 675 | 675 | $article = abs(intval($source['lastarticle'])); |
| 676 | - if($article > 0){ |
|
| 677 | - if($group_article_start[$ghash] == 0) |
|
| 676 | + if ($article > 0) { |
|
| 677 | + if ($group_article_start[$ghash] == 0) |
|
| 678 | 678 | $group_article_start[$ghash] = $article; |
| 679 | 679 | else |
| 680 | - $group_article_start[$ghash] = ($article < $group_article_start[$ghash])? |
|
| 681 | - $article:$group_article_start[$ghash]; |
|
| 680 | + $group_article_start[$ghash] = ($article < $group_article_start[$ghash]) ? |
|
| 681 | + $article : $group_article_start[$ghash]; |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | // Store id |
@@ -702,15 +702,15 @@ discard block |
||
| 702 | 702 | // We want to resort the internal arrays by they're ref time |
| 703 | 703 | // so that the oldest (longest without an update) is processed |
| 704 | 704 | // first |
| 705 | - foreach(array_keys($group_hash) as $key){ |
|
| 705 | + foreach (array_keys($group_hash) as $key) { |
|
| 706 | 706 | $_ref = []; |
| 707 | - foreach($group_hash[$key] as $id => $source){ |
|
| 707 | + foreach ($group_hash[$key] as $id => $source) { |
|
| 708 | 708 | # Source Time (within reason) |
| 709 | - if($backfill) |
|
| 709 | + if ($backfill) |
|
| 710 | 710 | $_ref[$id] = $_max_age; |
| 711 | 711 | else |
| 712 | 712 | $_ref[$id] = |
| 713 | - ($source['ref'] < $_max_age)?$_max_age:$source['ref']; |
|
| 713 | + ($source['ref'] < $_max_age) ? $_max_age : $source['ref']; |
|
| 714 | 714 | } |
| 715 | 715 | // Sort results (oldest in time first) |
| 716 | 716 | array_multisort($_ref, SORT_ASC, $group_hash[$key]); |
@@ -719,12 +719,12 @@ discard block |
||
| 719 | 719 | // Now we fetch headers |
| 720 | 720 | |
| 721 | 721 | // Connect to server |
| 722 | - try{ |
|
| 722 | + try { |
|
| 723 | 723 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 724 | 724 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | - catch(\Exception $e){ |
|
| 727 | + catch (\Exception $e) { |
|
| 728 | 728 | printf("Failed to connect to Usenet"); |
| 729 | 729 | return false; |
| 730 | 730 | } |
@@ -733,18 +733,18 @@ discard block |
||
| 733 | 733 | $inserted = 0; |
| 734 | 734 | $updated = 0; |
| 735 | 735 | |
| 736 | - foreach($group_hash as $group => $hash){ |
|
| 736 | + foreach ($group_hash as $group => $hash) { |
|
| 737 | 737 | printf("Spotnab : %d source(s)...", count($hash)); |
| 738 | 738 | |
| 739 | 739 | $summary = $this->_nntp->selectGroup($group); |
| 740 | 740 | // Get our article id |
| 741 | - $first = ($backfill)?0:$group_article_start[$group]; |
|
| 742 | - if($first == 0){ |
|
| 741 | + $first = ($backfill) ? 0 : $group_article_start[$group]; |
|
| 742 | + if ($first == 0) { |
|
| 743 | 743 | // We can safely use the first $hash entry since we've |
| 744 | 744 | // already sorted it in ascending order above, so this |
| 745 | 745 | // is the time furthest back |
| 746 | 746 | $first = $this->_first_article_by_date($group, $hash[0]['ref']); |
| 747 | - if($first === false){ |
|
| 747 | + if ($first === false) { |
|
| 748 | 748 | continue; |
| 749 | 749 | } |
| 750 | 750 | } |
@@ -752,10 +752,10 @@ discard block |
||
| 752 | 752 | // Group Processing Initialization |
| 753 | 753 | $processed = 0; |
| 754 | 754 | $batch = $last = intval($summary['last']); |
| 755 | - $total = abs($last-$first); |
|
| 755 | + $total = abs($last - $first); |
|
| 756 | 756 | |
| 757 | 757 | // Select Group |
| 758 | - while($fetch_okay && $processed < $total) |
|
| 758 | + while ($fetch_okay && $processed < $total) |
|
| 759 | 759 | { |
| 760 | 760 | try |
| 761 | 761 | { |
@@ -764,12 +764,12 @@ discard block |
||
| 764 | 764 | $batch = $first + SpotNab::FETCH_USENET_BATCH; |
| 765 | 765 | |
| 766 | 766 | // Batch Processing |
| 767 | - while ($processed>=0 && $processed < $total) |
|
| 767 | + while ($processed >= 0 && $processed < $total) |
|
| 768 | 768 | { |
| 769 | 769 | $headers = $this->_get_headers($group, |
| 770 | 770 | "$first-$batch", $retries); |
| 771 | 771 | |
| 772 | - if($headers === false){ |
|
| 772 | + if ($headers === false) { |
|
| 773 | 773 | // Retry Atempts exausted |
| 774 | 774 | $fetch_okay = false; |
| 775 | 775 | break; |
@@ -777,33 +777,33 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | // Process the header batch |
| 779 | 779 | $saved = $this->process_comment_headers($headers, $hash); |
| 780 | - if($saved !== false) |
|
| 780 | + if ($saved !== false) |
|
| 781 | 781 | { |
| 782 | 782 | $inserted += $saved[0]; |
| 783 | 783 | $updated += $saved[1]; |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | - $processed += ($batch-$first); |
|
| 786 | + $processed += ($batch - $first); |
|
| 787 | 787 | // Increment starting index |
| 788 | - $first += ($batch-$first); |
|
| 788 | + $first += ($batch - $first); |
|
| 789 | 789 | |
| 790 | - if ($last-$first >= SpotNab::FETCH_USENET_BATCH){ |
|
| 790 | + if ($last - $first >= SpotNab::FETCH_USENET_BATCH) { |
|
| 791 | 791 | // Fetch next batch |
| 792 | 792 | $batch = $first + SpotNab::FETCH_USENET_BATCH; |
| 793 | - }else{ |
|
| 793 | + } else { |
|
| 794 | 794 | $batch = $last; |
| 795 | 795 | } |
| 796 | 796 | //echo "$first-$batch, processed=$processed\n"; |
| 797 | 797 | //print_r($headers); |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | - }catch(\Exception $e){ |
|
| 800 | + } catch (\Exception $e) { |
|
| 801 | 801 | // Reset Connection |
| 802 | 802 | $fetch_okay = $this->_nntpReset($group); |
| 803 | 803 | |
| 804 | 804 | // Track retry attempts |
| 805 | 805 | $retries--; |
| 806 | - if($retries <= 0){ |
|
| 806 | + if ($retries <= 0) { |
|
| 807 | 807 | // Retry Atempts exausted |
| 808 | 808 | $fetch_okay = false; |
| 809 | 809 | break; |
@@ -818,14 +818,14 @@ discard block |
||
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | // Ensure We're not connected |
| 821 | - try{$this->_nntp->doQuit();} |
|
| 822 | - catch(\Exception $e) |
|
| 821 | + try {$this->_nntp->doQuit(); } |
|
| 822 | + catch (\Exception $e) |
|
| 823 | 823 | {/* do nothing */} |
| 824 | 824 | |
| 825 | 825 | return $inserted + $updated; |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - public function processGID($limit=500, $batch=5000, $delete_broken_releases = false){ |
|
| 828 | + public function processGID($limit = 500, $batch = 5000, $delete_broken_releases = false) { |
|
| 829 | 829 | // Process until someone presses cntrl-c |
| 830 | 830 | |
| 831 | 831 | $nzb = new NZB(); |
@@ -839,30 +839,30 @@ discard block |
||
| 839 | 839 | .'WHERE gid IS NULL ORDER BY adddate DESC LIMIT %d,%d'; |
| 840 | 840 | $usql = "UPDATE releases SET gid = '%s' WHERE id = %d"; |
| 841 | 841 | |
| 842 | - while(1){ |
|
| 842 | + while (1) { |
|
| 843 | 843 | // finish |
| 844 | - if($limit > 0 && $processed >= $limit) |
|
| 844 | + if ($limit > 0 && $processed >= $limit) |
|
| 845 | 845 | break; |
| 846 | - $batch=($limit > 0 && $batch > $limit)?$limit:$batch; |
|
| 846 | + $batch = ($limit > 0 && $batch > $limit) ? $limit : $batch; |
|
| 847 | 847 | $res = $this->_pdo->query(sprintf($fsql, $offset, $batch)); |
| 848 | - if(!$res)break; |
|
| 849 | - if(count($res) <= 0)break; |
|
| 848 | + if (!$res)break; |
|
| 849 | + if (count($res) <= 0)break; |
|
| 850 | 850 | $offset += $batch; |
| 851 | 851 | |
| 852 | - foreach ($res as $r){ |
|
| 852 | + foreach ($res as $r) { |
|
| 853 | 853 | $nzbfile = $nzb->getNZBPath($r["guid"]); |
| 854 | - if($nzbfile === NULL){ |
|
| 854 | + if ($nzbfile === NULL) { |
|
| 855 | 855 | continue; |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | $nzbInfo = new NZBInfo(); |
| 859 | 859 | if (!$nzbInfo->loadFromFile($nzbfile)) |
| 860 | 860 | { |
| 861 | - if($delete_broken_releases){ |
|
| 861 | + if ($delete_broken_releases) { |
|
| 862 | 862 | $this->releases->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage); |
| 863 | 863 | // Free the variable in an attempt to recover memory |
| 864 | 864 | echo '-'; |
| 865 | - }else{ |
|
| 865 | + } else { |
|
| 866 | 866 | // Skip over this one for future fetches |
| 867 | 867 | $offset++; |
| 868 | 868 | } |
@@ -874,11 +874,11 @@ discard block |
||
| 874 | 874 | // Free the variable in an attempt to recover memory |
| 875 | 875 | unset($nzbInfo); |
| 876 | 876 | |
| 877 | - if(!$gid){ |
|
| 878 | - if($delete_broken_releases){ |
|
| 877 | + if (!$gid) { |
|
| 878 | + if ($delete_broken_releases) { |
|
| 879 | 879 | $this->releases->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage); |
| 880 | 880 | echo '-'; |
| 881 | - }else{ |
|
| 881 | + } else { |
|
| 882 | 882 | // Skip over this one for future fetches |
| 883 | 883 | $offset++; |
| 884 | 884 | } |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | |
| 888 | 888 | // Update DB With Global Identifer |
| 889 | 889 | $ures = $this->_pdo->queryExec(sprintf("UPDATE releases SET gid = %s WHERE id = %d", $this->_pdo->escapeString($gid), $r['id'])); |
| 890 | - if($ures->rowCount() == 0){ |
|
| 890 | + if ($ures->rowCount() == 0) { |
|
| 891 | 891 | printf("\nPostPrc : Failed to update: %s\n", $r['name']); |
| 892 | 892 | } |
| 893 | 893 | // make noise... |
@@ -906,13 +906,13 @@ discard block |
||
| 906 | 906 | ) |
| 907 | 907 | ); |
| 908 | 908 | $rows = $affected->rowCount(); |
| 909 | - if($rows > 0) |
|
| 909 | + if ($rows > 0) |
|
| 910 | 910 | $processed += $rows; |
| 911 | 911 | return $processed; |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | // *********************************************************************** |
| 915 | - public function keygen($print = true, $force_regen = false){ |
|
| 915 | + public function keygen($print = true, $force_regen = false) { |
|
| 916 | 916 | // Simply generate a Public/Private Key pair if they don't already |
| 917 | 917 | // exist |
| 918 | 918 | |
@@ -920,17 +920,17 @@ discard block |
||
| 920 | 920 | // a few checks first to make sure it's safe to do so |
| 921 | 921 | $do_keygen = true; |
| 922 | 922 | |
| 923 | - if($force_regen === false){ |
|
| 923 | + if ($force_regen === false) { |
|
| 924 | 924 | // Not forcing, so we immediately toggle the keygen |
| 925 | 925 | // flag, we'll toggle it back if we feel the need |
| 926 | 926 | $do_keygen = false; |
| 927 | 927 | |
| 928 | - if($this->_ssl_pubkey && $this->_ssl_prvkey){ |
|
| 928 | + if ($this->_ssl_pubkey && $this->_ssl_prvkey) { |
|
| 929 | 929 | |
| 930 | 930 | $str_in = $this->getRandomStr(80); |
| 931 | 931 | $str_out = $this->decrypt($this->encrypt($str_in)); |
| 932 | 932 | |
| 933 | - if($str_in != $str_out){ |
|
| 933 | + if ($str_in != $str_out) { |
|
| 934 | 934 | // Our key isn't good for nothin... |
| 935 | 935 | // regen a new one |
| 936 | 936 | $do_keygen = true; |
@@ -938,15 +938,15 @@ discard block |
||
| 938 | 938 | } |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - if($do_keygen) |
|
| 941 | + if ($do_keygen) |
|
| 942 | 942 | { |
| 943 | 943 | // Set new Key |
| 944 | 944 | $keys = $this->_keygen(); |
| 945 | - if(is_array($keys)){ |
|
| 945 | + if (is_array($keys)) { |
|
| 946 | 946 | // Force New Username |
| 947 | 947 | $sql = sprintf("Update settings SET value = %s " |
| 948 | 948 | ."WHERE setting = 'spotnabuser'", |
| 949 | - $this->_pdo->escapeString(sprintf("nntp-%s",substr(md5($keys['pubkey']), 0, 4)))); |
|
| 949 | + $this->_pdo->escapeString(sprintf("nntp-%s", substr(md5($keys['pubkey']), 0, 4)))); |
|
| 950 | 950 | $this->_pdo->queryExec($sql); |
| 951 | 951 | // Force New Email |
| 952 | 952 | $sql = sprintf("Update settings SET value = %s " |
@@ -957,13 +957,13 @@ discard block |
||
| 957 | 957 | ))); |
| 958 | 958 | $this->_pdo->queryExec($sql); |
| 959 | 959 | // Save Keys |
| 960 | - $sql = sprintf("Update settings SET value = %s ". |
|
| 960 | + $sql = sprintf("Update settings SET value = %s " . |
|
| 961 | 961 | "WHERE setting = 'spotnabsitepubkey'", |
| 962 | 962 | $this->_pdo->escapeString($keys['pubkey'])); |
| 963 | 963 | $this->_pdo->queryExec($sql); |
| 964 | 964 | //echo $keys['pubkey']."\n"; |
| 965 | 965 | |
| 966 | - $sql = sprintf("Update settings SET value = %s ". |
|
| 966 | + $sql = sprintf("Update settings SET value = %s " . |
|
| 967 | 967 | "WHERE setting = 'spotnabsiteprvkey'", |
| 968 | 968 | $this->_pdo->escapeString($keys['prvkey'])); |
| 969 | 969 | $this->_pdo->queryExec($sql); |
@@ -973,13 +973,13 @@ discard block |
||
| 973 | 973 | $this->_post_email = trim($this->_pdo->getSetting('spotnabemail')); |
| 974 | 974 | $this->_ssl_pubkey = $this->decompstr($this->_pdo->getSetting('spotnabsitepubkey')); |
| 975 | 975 | $this->_ssl_prvkey = $this->decompstr($this->_pdo->getSetting('spotnabsiteprvkey')); |
| 976 | - }else{ |
|
| 976 | + } else { |
|
| 977 | 977 | // echo "Failed."; |
| 978 | 978 | return false; |
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - if($print){ |
|
| 982 | + if ($print) { |
|
| 983 | 983 | printf("SPOTNAB USER : %s\n", $this->_post_user); |
| 984 | 984 | printf("SPOTNAB EMAIL : %s\n", $this->_post_email); |
| 985 | 985 | printf("SPOTNAB GROUP : %s\n", $this->_post_group); |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | // *********************************************************************** |
| 997 | - protected function _first_article_by_date($group, $refdate, $limit = SpotNab::FETCH_MAXIMUM_HEADERS, $retries=3){ |
|
| 997 | + protected function _first_article_by_date($group, $refdate, $limit = SpotNab::FETCH_MAXIMUM_HEADERS, $retries = 3) { |
|
| 998 | 998 | // fetches the first article starting at the time specified |
| 999 | 999 | // by ref time. |
| 1000 | 1000 | // |
@@ -1021,12 +1021,12 @@ discard block |
||
| 1021 | 1021 | // no one is perfect right? |
| 1022 | 1022 | $curfew = 10; |
| 1023 | 1023 | |
| 1024 | - if(is_string($refdate)){ |
|
| 1024 | + if (is_string($refdate)) { |
|
| 1025 | 1025 | // Convert to Integer (Local Time) |
| 1026 | 1026 | $refdate = strtotime($refdate); |
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | - while(($retries > 0) && ($interval > 0)){ |
|
| 1029 | + while (($retries > 0) && ($interval > 0)) { |
|
| 1030 | 1030 | $summary = $this->_nntp->selectGroup($group); |
| 1031 | 1031 | |
| 1032 | 1032 | $_last = $last = intval($summary['last']); |
@@ -1035,56 +1035,56 @@ discard block |
||
| 1035 | 1035 | $curdate = $lastdate = NULL; |
| 1036 | 1036 | $curid = $lastid = $first; |
| 1037 | 1037 | $interval = 0; |
| 1038 | - while($retries > 0){ |
|
| 1038 | + while ($retries > 0) { |
|
| 1039 | 1039 | |
| 1040 | 1040 | // Save Last Interval |
| 1041 | 1041 | $lastinterval = $interval; |
| 1042 | 1042 | |
| 1043 | 1043 | // Adjust Interval |
| 1044 | - if(($last - $first) > 3) |
|
| 1045 | - $interval = floor(($last - $first)/2); |
|
| 1044 | + if (($last - $first) > 3) |
|
| 1045 | + $interval = floor(($last - $first) / 2); |
|
| 1046 | 1046 | else |
| 1047 | 1047 | $interval = 1; |
| 1048 | 1048 | |
| 1049 | - if($misses >= SpotNab::FETCH_MAX_MISSES){ |
|
| 1049 | + if ($misses >= SpotNab::FETCH_MAX_MISSES) { |
|
| 1050 | 1050 | // Misses reached |
| 1051 | 1051 | $last = intval($summary['last']); |
| 1052 | 1052 | // Adjust pointer |
| 1053 | - $lastid = ($lastid=== false)?$first:$lastid; |
|
| 1054 | - if($lastid >0){ |
|
| 1055 | - if (($last-$lastid) > $limit){ |
|
| 1053 | + $lastid = ($lastid === false) ? $first : $lastid; |
|
| 1054 | + if ($lastid > 0) { |
|
| 1055 | + if (($last - $lastid) > $limit) { |
|
| 1056 | 1056 | // We exceeded our maximum header limit |
| 1057 | 1057 | // adjust accordingly |
| 1058 | 1058 | $lastid = $last - $limit; |
| 1059 | 1059 | } |
| 1060 | - echo " ".(abs($last-$lastid))." record(s) back."; |
|
| 1060 | + echo " " . (abs($last - $lastid)) . " record(s) back."; |
|
| 1061 | 1061 | return $lastid; |
| 1062 | - }else{ |
|
| 1063 | - if (($_last-$last) > $limit){ |
|
| 1062 | + } else { |
|
| 1063 | + if (($_last - $last) > $limit) { |
|
| 1064 | 1064 | // We exceeded our maximum header limit |
| 1065 | 1065 | // adjust accordingly |
| 1066 | 1066 | $last = $_last - $limit; |
| 1067 | 1067 | } |
| 1068 | - echo " ".(abs($_last-$last))." record(s) back."; |
|
| 1068 | + echo " " . (abs($_last - $last)) . " record(s) back."; |
|
| 1069 | 1069 | return $last; |
| 1070 | 1070 | } |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | // Swap |
| 1074 | 1074 | $lastdate = $curdate; |
| 1075 | - if($curid > 0) |
|
| 1075 | + if ($curid > 0) |
|
| 1076 | 1076 | $lastid = $curid; |
| 1077 | 1077 | |
| 1078 | 1078 | $msgs = $this->_get_headers( |
| 1079 | - $group, ($last-$interval), $retries); |
|
| 1079 | + $group, ($last - $interval), $retries); |
|
| 1080 | 1080 | |
| 1081 | - if($msgs === false){ |
|
| 1082 | - if (($_last-$last) > $limit){ |
|
| 1081 | + if ($msgs === false) { |
|
| 1082 | + if (($_last - $last) > $limit) { |
|
| 1083 | 1083 | // We exceeded our maximum header limit |
| 1084 | 1084 | // adjust accordingly |
| 1085 | 1085 | $last = $_last - $limit; |
| 1086 | 1086 | } |
| 1087 | - echo " ".(abs($_last-$last))." record(s) back."; |
|
| 1087 | + echo " " . (abs($_last - $last)) . " record(s) back."; |
|
| 1088 | 1088 | return $last; |
| 1089 | 1089 | } |
| 1090 | 1090 | |
@@ -1094,72 +1094,72 @@ discard block |
||
| 1094 | 1094 | // Save Tracker |
| 1095 | 1095 | $curdate = strtotime($msgs[0]['Date']); |
| 1096 | 1096 | $curid = intval($msgs[0]['Number']); |
| 1097 | - if($curid <= 0){ |
|
| 1098 | - $lastid = ($lastid=== false)?$first:$lastid; |
|
| 1099 | - if($lastid >0){ |
|
| 1100 | - if (($_last-$lastid) > $limit){ |
|
| 1097 | + if ($curid <= 0) { |
|
| 1098 | + $lastid = ($lastid === false) ? $first : $lastid; |
|
| 1099 | + if ($lastid > 0) { |
|
| 1100 | + if (($_last - $lastid) > $limit) { |
|
| 1101 | 1101 | // We exceeded our maximum header limit |
| 1102 | 1102 | // adjust accordingly |
| 1103 | 1103 | $lastid = $_last - $limit; |
| 1104 | 1104 | } |
| 1105 | - echo " ".(abs($_last-$lastid))." record(s) back."; |
|
| 1105 | + echo " " . (abs($_last - $lastid)) . " record(s) back."; |
|
| 1106 | 1106 | return $lastid; |
| 1107 | - }else{ |
|
| 1108 | - if (($_last-$last) > $limit){ |
|
| 1107 | + } else { |
|
| 1108 | + if (($_last - $last) > $limit) { |
|
| 1109 | 1109 | // We exceeded our maximum header limit |
| 1110 | 1110 | // adjust accordingly |
| 1111 | 1111 | $last = $_last - $limit; |
| 1112 | 1112 | } |
| 1113 | - echo " ".(abs($_last-$last))." record(s) back."; |
|
| 1113 | + echo " " . (abs($_last - $last)) . " record(s) back."; |
|
| 1114 | 1114 | return $last; |
| 1115 | 1115 | } |
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | - if($interval == 1){ |
|
| 1118 | + if ($interval == 1) { |
|
| 1119 | 1119 | // We're soo close now... |
| 1120 | - $curfew --; |
|
| 1121 | - if($curfew <= 0) |
|
| 1120 | + $curfew--; |
|
| 1121 | + if ($curfew <= 0) |
|
| 1122 | 1122 | { |
| 1123 | - if (($_last-$curid) > $limit){ |
|
| 1123 | + if (($_last - $curid) > $limit) { |
|
| 1124 | 1124 | // We exceeded our maximum header limit |
| 1125 | 1125 | // adjust accordingly |
| 1126 | 1126 | $curid = $_last - $limit; |
| 1127 | 1127 | } |
| 1128 | 1128 | // curfew met... just deal with our current spot |
| 1129 | - echo " ".($_last-$curid)." record(s) back."; |
|
| 1129 | + echo " " . ($_last - $curid) . " record(s) back."; |
|
| 1130 | 1130 | return $curid; |
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | - if($refdate > $curdate && $refdate > $lastdate){ |
|
| 1134 | - if (($_last-$curid) > $limit){ |
|
| 1133 | + if ($refdate > $curdate && $refdate > $lastdate) { |
|
| 1134 | + if (($_last - $curid) > $limit) { |
|
| 1135 | 1135 | // We exceeded our maximum header limit |
| 1136 | 1136 | // adjust accordingly |
| 1137 | 1137 | $curid = $_last - $limit; |
| 1138 | 1138 | } |
| 1139 | 1139 | // Found content |
| 1140 | - echo " ".($_last-$curid)." record(s) back."; |
|
| 1140 | + echo " " . ($_last - $curid) . " record(s) back."; |
|
| 1141 | 1141 | return $curid; |
| 1142 | - }else if($refdate > $curdate && $refdate > $lastdate){ |
|
| 1142 | + } else if ($refdate > $curdate && $refdate > $lastdate) { |
|
| 1143 | 1143 | // Close... Shuffle forward a bit |
| 1144 | - $first+=2; |
|
| 1145 | - }else{ |
|
| 1144 | + $first += 2; |
|
| 1145 | + } else { |
|
| 1146 | 1146 | // Slide window and try again |
| 1147 | - $last-=2; |
|
| 1147 | + $last -= 2; |
|
| 1148 | 1148 | } |
| 1149 | - $interval=2; |
|
| 1149 | + $interval = 2; |
|
| 1150 | 1150 | continue; |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | // Make some noise |
| 1154 | - if($interval%2)echo "."; |
|
| 1154 | + if ($interval % 2)echo "."; |
|
| 1155 | 1155 | |
| 1156 | 1156 | // Adjust Boundaries |
| 1157 | - if($curdate > $refdate){ |
|
| 1157 | + if ($curdate > $refdate) { |
|
| 1158 | 1158 | // We need to look further forward |
| 1159 | - $last = $curid+1; |
|
| 1160 | - }else if ($curdate <= $refdate){ |
|
| 1159 | + $last = $curid + 1; |
|
| 1160 | + } else if ($curdate <= $refdate) { |
|
| 1161 | 1161 | // We need To look further back |
| 1162 | - $first = $curid-1; |
|
| 1162 | + $first = $curid - 1; |
|
| 1163 | 1163 | } |
| 1164 | 1164 | } |
| 1165 | 1165 | } |
@@ -1168,7 +1168,7 @@ discard block |
||
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | // *********************************************************************** |
| 1171 | - public function process_comment_headers($headers, $group_hash, $save = true){ |
|
| 1171 | + public function process_comment_headers($headers, $group_hash, $save = true) { |
|
| 1172 | 1172 | /* |
| 1173 | 1173 | * We iterate over the provided headers (generated by |
| 1174 | 1174 | * $this->_get_headers() to a structure that is at the very |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | * ) |
| 1210 | 1210 | */ |
| 1211 | 1211 | |
| 1212 | - if(!count($group_hash)){ |
|
| 1212 | + if (!count($group_hash)) { |
|
| 1213 | 1213 | // Nothing to process |
| 1214 | 1214 | return []; |
| 1215 | 1215 | } |
@@ -1220,49 +1220,49 @@ discard block |
||
| 1220 | 1220 | |
| 1221 | 1221 | |
| 1222 | 1222 | // Comments |
| 1223 | - $sql_new_cmt = "INSERT INTO release_comments (". |
|
| 1224 | - "id, sourceid, username, users_id, gid, cid, isvisible, ". |
|
| 1225 | - "releases_id, text, createddate, issynced, nzb_guid) VALUES (". |
|
| 1223 | + $sql_new_cmt = "INSERT INTO release_comments (" . |
|
| 1224 | + "id, sourceid, username, users_id, gid, cid, isvisible, " . |
|
| 1225 | + "releases_id, text, createddate, issynced, nzb_guid) VALUES (" . |
|
| 1226 | 1226 | "NULL, %d, %s, 0, %s, %s, %d, 0, %s, %s, 1, UNHEX(%s))"; |
| 1227 | - $sql_upd_cmt = "UPDATE release_comments SET ". |
|
| 1228 | - "isvisible = %d, text = %s". |
|
| 1227 | + $sql_upd_cmt = "UPDATE release_comments SET " . |
|
| 1228 | + "isvisible = %d, text = %s" . |
|
| 1229 | 1229 | "WHERE sourceid = %d AND gid = %s AND cid = %s AND nzb_guid = UNHEX(%s)"; |
| 1230 | - $sql_fnd_cmt = "SELECT count(id) as cnt FROM release_comments ". |
|
| 1230 | + $sql_fnd_cmt = "SELECT count(id) as cnt FROM release_comments " . |
|
| 1231 | 1231 | "WHERE sourceid = %d AND gid = %s AND cid = %s"; |
| 1232 | 1232 | |
| 1233 | 1233 | // Sync Times |
| 1234 | - $sql_sync = "UPDATE spotnabsources SET lastupdate = %s ". |
|
| 1234 | + $sql_sync = "UPDATE spotnabsources SET lastupdate = %s " . |
|
| 1235 | 1235 | "WHERE id = %d"; |
| 1236 | 1236 | |
| 1237 | 1237 | $matches = NULL; |
| 1238 | 1238 | $processed = 0; |
| 1239 | 1239 | $updates = 0; |
| 1240 | 1240 | $inserts = 0; |
| 1241 | - foreach ($headers as $header){ |
|
| 1241 | + foreach ($headers as $header) { |
|
| 1242 | 1242 | // Preform some general scanning the header to determine |
| 1243 | 1243 | // if it could possibly be a valid post. |
| 1244 | - if(!preg_match(SpotNab::FETCH_MSGID_REGEX, |
|
| 1245 | - $header['Message-ID'], $matches)){ |
|
| 1244 | + if (!preg_match(SpotNab::FETCH_MSGID_REGEX, |
|
| 1245 | + $header['Message-ID'], $matches)) { |
|
| 1246 | 1246 | continue; |
| 1247 | 1247 | } |
| 1248 | - if($matches['domain'] != SpotNab::SEGID_DOMAIN) |
|
| 1248 | + if ($matches['domain'] != SpotNab::SEGID_DOMAIN) |
|
| 1249 | 1249 | continue; |
| 1250 | 1250 | |
| 1251 | - if($matches['type'] != SpotNab::FETCH_COMMENT_TYPE) |
|
| 1251 | + if ($matches['type'] != SpotNab::FETCH_COMMENT_TYPE) |
|
| 1252 | 1252 | continue; |
| 1253 | 1253 | |
| 1254 | 1254 | // Now we check the subject line; it provides the first part of |
| 1255 | 1255 | // the key to determining if we should handle the message or not |
| 1256 | - if(!preg_match(SpotNab::FETCH_COMMENT_SUBJECT_REGEX, |
|
| 1257 | - $header['Subject'], $matches)){ |
|
| 1256 | + if (!preg_match(SpotNab::FETCH_COMMENT_SUBJECT_REGEX, |
|
| 1257 | + $header['Subject'], $matches)) { |
|
| 1258 | 1258 | continue; |
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | // We have a match; So populate potential variables |
| 1262 | 1262 | $checksum = $matches['checksum']; |
| 1263 | 1263 | $refdate = $matches['utcref']; |
| 1264 | - $refdate_epoch = @strtotime($matches['utcref']. " UTC"); |
|
| 1265 | - if($refdate_epoch === false || $refdate_epoch < 0){ |
|
| 1264 | + $refdate_epoch = @strtotime($matches['utcref'] . " UTC"); |
|
| 1265 | + if ($refdate_epoch === false || $refdate_epoch < 0) { |
|
| 1266 | 1266 | // Bad time specified |
| 1267 | 1267 | continue; |
| 1268 | 1268 | } |
@@ -1271,26 +1271,26 @@ discard block |
||
| 1271 | 1271 | // assume the body will decode too (and won't be a waste of |
| 1272 | 1272 | // time to download it) |
| 1273 | 1273 | |
| 1274 | - foreach($group_hash as $hash){ |
|
| 1274 | + foreach ($group_hash as $hash) { |
|
| 1275 | 1275 | // Track how many records we handled |
| 1276 | 1276 | $processed++; |
| 1277 | 1277 | |
| 1278 | 1278 | // First check the ref date... if it's newer then what we've |
| 1279 | 1279 | // already processed, then we'll just keep on chugging along. |
| 1280 | - if($refdate_epoch <= $hash['ref']){ |
|
| 1280 | + if ($refdate_epoch <= $hash['ref']) { |
|
| 1281 | 1281 | continue; |
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | // Scan header information for supported matches |
| 1285 | - if(!preg_match('/^(?P<user>[^<]+)<(?P<email>[^>]+)>$/', |
|
| 1285 | + if (!preg_match('/^(?P<user>[^<]+)<(?P<email>[^>]+)>$/', |
|
| 1286 | 1286 | $header['From'], $matches)) |
| 1287 | 1287 | continue; |
| 1288 | 1288 | |
| 1289 | 1289 | // Match against our sources posts |
| 1290 | - if(trim($matches['user']) != $hash['user']) { |
|
| 1290 | + if (trim($matches['user']) != $hash['user']) { |
|
| 1291 | 1291 | continue; |
| 1292 | 1292 | } |
| 1293 | - if(trim($matches['email']) != $hash['email']) { |
|
| 1293 | + if (trim($matches['email']) != $hash['email']) { |
|
| 1294 | 1294 | continue; |
| 1295 | 1295 | } |
| 1296 | 1296 | |
@@ -1302,55 +1302,55 @@ discard block |
||
| 1302 | 1302 | // within the body matches that of the header... then we |
| 1303 | 1303 | // can start processing the guts of the body. |
| 1304 | 1304 | |
| 1305 | - if($save) { |
|
| 1305 | + if ($save) { |
|
| 1306 | 1306 | // Download Body |
| 1307 | 1307 | $body = $this->_get_body($header['Group'], $header['Message-ID']); |
| 1308 | - if($body === false) { |
|
| 1308 | + if ($body === false) { |
|
| 1309 | 1309 | continue; |
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | // Decode Body |
| 1313 | 1313 | $body = $this->decodePost($body, $hash['key']); |
| 1314 | - if($body === false) { |
|
| 1314 | + if ($body === false) { |
|
| 1315 | 1315 | continue; // Decode failed |
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | 1318 | // Verify Body |
| 1319 | - if(!is_array($body)) { |
|
| 1319 | + if (!is_array($body)) { |
|
| 1320 | 1320 | continue; // not any array |
| 1321 | 1321 | } |
| 1322 | 1322 | |
| 1323 | - if(!(bool)count(array_filter(array_keys($body), 'is_string'))) { |
|
| 1323 | + if (!(bool)count(array_filter(array_keys($body), 'is_string'))) { |
|
| 1324 | 1324 | continue; // not an associative array |
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | - if((!array_key_exists('server', $body)) || (!array_key_exists('postdate_utc', $body))) { |
|
| 1327 | + if ((!array_key_exists('server', $body)) || (!array_key_exists('postdate_utc', $body))) { |
|
| 1328 | 1328 | continue; // base structure missing |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | // Compare postdate_utc and ensure it matches header |
| 1332 | 1332 | // timestamp |
| 1333 | - if(preg_replace('/[^0-9]/', '', $body['postdate_utc']) != $refdate) { |
|
| 1333 | + if (preg_replace('/[^0-9]/', '', $body['postdate_utc']) != $refdate) { |
|
| 1334 | 1334 | continue; |
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | // Comment Handling |
| 1338 | - if(array_key_exists('comments',$body) && is_array($body['comments'])) { |
|
| 1338 | + if (array_key_exists('comments', $body) && is_array($body['comments'])) { |
|
| 1339 | 1339 | $rc = new ReleaseComments(); |
| 1340 | 1340 | |
| 1341 | - foreach($body['comments'] as $comment){ |
|
| 1341 | + foreach ($body['comments'] as $comment) { |
|
| 1342 | 1342 | |
| 1343 | 1343 | // Verify Comment is parseable |
| 1344 | - if(!is_array($comment)) { |
|
| 1344 | + if (!is_array($comment)) { |
|
| 1345 | 1345 | continue; // not an array |
| 1346 | 1346 | } |
| 1347 | - if(!count(array_filter(array_keys($comment)))) { |
|
| 1347 | + if (!count(array_filter(array_keys($comment)))) { |
|
| 1348 | 1348 | continue; // not an associative array |
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | // Store isvisible flag |
| 1352 | 1352 | $is_visible = 1; |
| 1353 | - if(array_key_exists('is_visible', $comment)) { |
|
| 1353 | + if (array_key_exists('is_visible', $comment)) { |
|
| 1354 | 1354 | $is_visible = (intval($comment['is_visible']) > 0) ? 1 : 0; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
@@ -1362,7 +1362,7 @@ discard block |
||
| 1362 | 1362 | $this->_pdo->escapeString($comment['cid']))); |
| 1363 | 1363 | |
| 1364 | 1364 | // Store Results in DB |
| 1365 | - if($res && intval($res['cnt'])>0) { |
|
| 1365 | + if ($res && intval($res['cnt']) > 0) { |
|
| 1366 | 1366 | // Make some noise |
| 1367 | 1367 | echo '.'; |
| 1368 | 1368 | $updates += ($this->_pdo->queryExec(sprintf($sql_upd_cmt, |
@@ -1372,7 +1372,7 @@ discard block |
||
| 1372 | 1372 | $this->_pdo->escapeString($comment['gid']), |
| 1373 | 1373 | $this->_pdo->escapeString($comment['cid']), |
| 1374 | 1374 | $this->_pdo->escapeString($comment['gid']) |
| 1375 | - ))>0)?1:0; |
|
| 1375 | + )) > 0) ? 1 : 0; |
|
| 1376 | 1376 | } else { |
| 1377 | 1377 | // Make some noise |
| 1378 | 1378 | echo '+'; |
@@ -1402,7 +1402,7 @@ discard block |
||
| 1402 | 1402 | $hash['id'] |
| 1403 | 1403 | ) |
| 1404 | 1404 | ); |
| 1405 | - }else{ |
|
| 1405 | + } else { |
|
| 1406 | 1406 | // Debug non/save mode; mark update |
| 1407 | 1407 | $updates += 1; |
| 1408 | 1408 | } |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | // *********************************************************************** |
| 1421 | - public function process_discovery_headers($headers, $save = true){ |
|
| 1421 | + public function process_discovery_headers($headers, $save = true) { |
|
| 1422 | 1422 | /* |
| 1423 | 1423 | * We iterate over the provided headers (generated by |
| 1424 | 1424 | * $this->_get_headers() to a structure that is at the very |
@@ -1444,51 +1444,51 @@ discard block |
||
| 1444 | 1444 | // |
| 1445 | 1445 | |
| 1446 | 1446 | // Auto Enable Flag (used for inserts only) |
| 1447 | - $auto_enable = ($this->_auto_enable)?"1":"0"; |
|
| 1447 | + $auto_enable = ($this->_auto_enable) ? "1" : "0"; |
|
| 1448 | 1448 | |
| 1449 | 1449 | // Spotnab Sources |
| 1450 | - $sql_new_cmt = "INSERT INTO spotnabsources (". |
|
| 1451 | - "id, username, useremail, usenetgroup, publickey, ". |
|
| 1452 | - "active, description, lastupdate, lastbroadcast, dateadded) VALUES (". |
|
| 1450 | + $sql_new_cmt = "INSERT INTO spotnabsources (" . |
|
| 1451 | + "id, username, useremail, usenetgroup, publickey, " . |
|
| 1452 | + "active, description, lastupdate, lastbroadcast, dateadded) VALUES (" . |
|
| 1453 | 1453 | "NULL, %s, %s, %s, %s, $auto_enable, %s, NULL, %s, NOW())"; |
| 1454 | - $sql_upd_cmt = "UPDATE spotnabsources SET ". |
|
| 1455 | - "lastbroadcast = %s ". |
|
| 1454 | + $sql_upd_cmt = "UPDATE spotnabsources SET " . |
|
| 1455 | + "lastbroadcast = %s " . |
|
| 1456 | 1456 | "WHERE username = %s AND useremail = %s AND usenetgroup = %s"; |
| 1457 | - $sql_fnd_cmt = "SELECT count(id) as cnt FROM spotnabsources ". |
|
| 1457 | + $sql_fnd_cmt = "SELECT count(id) as cnt FROM spotnabsources " . |
|
| 1458 | 1458 | "WHERE username = %s AND useremail = %s AND usenetgroup = %s"; |
| 1459 | 1459 | |
| 1460 | 1460 | $matches = NULL; |
| 1461 | 1461 | $processed = 0; |
| 1462 | 1462 | $inserts = 0; |
| 1463 | 1463 | $updates = 0; |
| 1464 | - foreach ($headers as $header){ |
|
| 1464 | + foreach ($headers as $header) { |
|
| 1465 | 1465 | // Preform some general scanning the header to determine |
| 1466 | 1466 | // if it could possibly be a valid post. |
| 1467 | 1467 | |
| 1468 | 1468 | // Now we check the subject line; it provides the first part of |
| 1469 | 1469 | // the key to determining if we should handle the message or not |
| 1470 | - if(!preg_match(SpotNab::FETCH_MSGID_REGEX, |
|
| 1471 | - $header['Message-ID'], $matches)){ |
|
| 1470 | + if (!preg_match(SpotNab::FETCH_MSGID_REGEX, |
|
| 1471 | + $header['Message-ID'], $matches)) { |
|
| 1472 | 1472 | continue; |
| 1473 | 1473 | } |
| 1474 | - if($matches['domain'] != SpotNab::SEGID_DOMAIN) |
|
| 1474 | + if ($matches['domain'] != SpotNab::SEGID_DOMAIN) |
|
| 1475 | 1475 | continue; |
| 1476 | 1476 | |
| 1477 | - if($matches['type'] != SpotNab::FETCH_DISCOVERY_TYPE) |
|
| 1477 | + if ($matches['type'] != SpotNab::FETCH_DISCOVERY_TYPE) |
|
| 1478 | 1478 | continue; |
| 1479 | 1479 | |
| 1480 | 1480 | // Now we check the subject line; it provides the first part of |
| 1481 | 1481 | // the key to determining if we should handle the message or not |
| 1482 | - if(!preg_match(SpotNab::FETCH_DISCOVERY_SUBJECT_REGEX, |
|
| 1483 | - $header['Subject'], $matches)){ |
|
| 1482 | + if (!preg_match(SpotNab::FETCH_DISCOVERY_SUBJECT_REGEX, |
|
| 1483 | + $header['Subject'], $matches)) { |
|
| 1484 | 1484 | continue; |
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | // We have a match; So populate potential variables |
| 1488 | 1488 | $checksum = $matches['checksum']; |
| 1489 | 1489 | $refdate = $matches['utcref']; |
| 1490 | - $refdate_epoch = @strtotime($matches['utcref']. " UTC"); |
|
| 1491 | - if($refdate_epoch === false || $refdate_epoch < 0){ |
|
| 1490 | + $refdate_epoch = @strtotime($matches['utcref'] . " UTC"); |
|
| 1491 | + if ($refdate_epoch === false || $refdate_epoch < 0) { |
|
| 1492 | 1492 | // Bad time specified |
| 1493 | 1493 | continue; |
| 1494 | 1494 | } |
@@ -1501,14 +1501,14 @@ discard block |
||
| 1501 | 1501 | $processed++; |
| 1502 | 1502 | |
| 1503 | 1503 | // Scan header information for supported matches |
| 1504 | - if(!preg_match('/^(?P<user>[^<]+)<(?P<email>[^>]+)>$/', |
|
| 1504 | + if (!preg_match('/^(?P<user>[^<]+)<(?P<email>[^>]+)>$/', |
|
| 1505 | 1505 | $header['From'], $matches)) |
| 1506 | 1506 | continue; |
| 1507 | 1507 | |
| 1508 | 1508 | // Match against our sources posts |
| 1509 | - if(trim($matches['user']) != SpotNab::AUTODISCOVER_POST_USER) |
|
| 1509 | + if (trim($matches['user']) != SpotNab::AUTODISCOVER_POST_USER) |
|
| 1510 | 1510 | continue; |
| 1511 | - if(trim($matches['email']) != SpotNab::AUTODISCOVER_POST_EMAIL) |
|
| 1511 | + if (trim($matches['email']) != SpotNab::AUTODISCOVER_POST_EMAIL) |
|
| 1512 | 1512 | continue; |
| 1513 | 1513 | |
| 1514 | 1514 | // If we reach here, we've found a header we can process |
@@ -1519,11 +1519,11 @@ discard block |
||
| 1519 | 1519 | // within the body matches that of the header... then we |
| 1520 | 1520 | // can start processing the guts of the body. |
| 1521 | 1521 | |
| 1522 | - if($save){ |
|
| 1522 | + if ($save) { |
|
| 1523 | 1523 | // Download Body |
| 1524 | 1524 | $body = $this->_get_body($header['Group'], |
| 1525 | 1525 | $header['Message-ID']); |
| 1526 | - if($body === false){ |
|
| 1526 | + if ($body === false) { |
|
| 1527 | 1527 | continue; |
| 1528 | 1528 | } |
| 1529 | 1529 | |
@@ -1532,17 +1532,17 @@ discard block |
||
| 1532 | 1532 | $body, |
| 1533 | 1533 | $this->decompstr($this->_ssl_auto_pubkey) |
| 1534 | 1534 | ); |
| 1535 | - if($body === false) |
|
| 1535 | + if ($body === false) |
|
| 1536 | 1536 | continue; // Decode failed |
| 1537 | 1537 | |
| 1538 | 1538 | // Verify Body |
| 1539 | - if(!is_array($body)) |
|
| 1539 | + if (!is_array($body)) |
|
| 1540 | 1540 | continue; // not any array |
| 1541 | 1541 | |
| 1542 | - if(!(bool)count(array_filter(array_keys($body), 'is_string'))) |
|
| 1542 | + if (!(bool)count(array_filter(array_keys($body), 'is_string'))) |
|
| 1543 | 1543 | continue; // not an associative array |
| 1544 | 1544 | |
| 1545 | - if(!(array_key_exists('site', $body) && |
|
| 1545 | + if (!(array_key_exists('site', $body) && |
|
| 1546 | 1546 | array_key_exists('posts', $body) && |
| 1547 | 1547 | array_key_exists('comments', $body) && |
| 1548 | 1548 | array_key_exists('postdate_utc', $body))) |
@@ -1550,22 +1550,22 @@ discard block |
||
| 1550 | 1550 | |
| 1551 | 1551 | // Compare postdate_utc and ensure it matches header |
| 1552 | 1552 | // timestamp |
| 1553 | - if(preg_replace('/[^0-9]/', '', |
|
| 1553 | + if (preg_replace('/[^0-9]/', '', |
|
| 1554 | 1554 | $body['postdate_utc']) != $refdate) |
| 1555 | 1555 | continue; |
| 1556 | 1556 | |
| 1557 | 1557 | $posts = $body['posts']; |
| 1558 | - $p_user = array_key_exists('user', $posts)?trim($posts['user']):NULL; |
|
| 1559 | - $p_email = array_key_exists('email', $posts)?trim($posts['email']):NULL; |
|
| 1560 | - $p_group = array_key_exists('group', $posts)?trim($posts['group']):NULL; |
|
| 1561 | - $p_key = array_key_exists('public_key', $posts)?trim($posts['public_key']):NULL; |
|
| 1558 | + $p_user = array_key_exists('user', $posts) ? trim($posts['user']) : NULL; |
|
| 1559 | + $p_email = array_key_exists('email', $posts) ? trim($posts['email']) : NULL; |
|
| 1560 | + $p_group = array_key_exists('group', $posts) ? trim($posts['group']) : NULL; |
|
| 1561 | + $p_key = array_key_exists('public_key', $posts) ? trim($posts['public_key']) : NULL; |
|
| 1562 | 1562 | |
| 1563 | - if(!($p_user && $p_email && $p_group && $p_key)) |
|
| 1563 | + if (!($p_user && $p_email && $p_group && $p_key)) |
|
| 1564 | 1564 | // basic error checking |
| 1565 | 1565 | continue; |
| 1566 | 1566 | |
| 1567 | 1567 | // Check to make sure the discovery isn't 'this' site |
| 1568 | - if($p_user == $this->_post_user && $p_email == $this->_post_email) |
|
| 1568 | + if ($p_user == $this->_post_user && $p_email == $this->_post_email) |
|
| 1569 | 1569 | continue; |
| 1570 | 1570 | |
| 1571 | 1571 | // Check that comment doesn't already exist |
@@ -1575,12 +1575,12 @@ discard block |
||
| 1575 | 1575 | $this->_pdo->escapeString($p_group)) |
| 1576 | 1576 | ); |
| 1577 | 1577 | |
| 1578 | - if(!$res) |
|
| 1578 | + if (!$res) |
|
| 1579 | 1579 | // Uh oh |
| 1580 | 1580 | continue; |
| 1581 | 1581 | |
| 1582 | 1582 | // Store Results in DB |
| 1583 | - if(intval($res['cnt'])==0){ |
|
| 1583 | + if (intval($res['cnt']) == 0) { |
|
| 1584 | 1584 | // Make some noise |
| 1585 | 1585 | echo '+'; |
| 1586 | 1586 | // Perform Insert |
@@ -1594,7 +1594,7 @@ discard block |
||
| 1594 | 1594 | $this->_pdo->escapeString($this->utc2local($refdate))) |
| 1595 | 1595 | ); |
| 1596 | 1596 | $inserts += 1; |
| 1597 | - }else{ |
|
| 1597 | + } else { |
|
| 1598 | 1598 | echo '.'; |
| 1599 | 1599 | $res = $this->_pdo->queryExec(sprintf($sql_upd_cmt, |
| 1600 | 1600 | $this->_pdo->escapeString($this->utc2local($refdate)), |
@@ -1609,14 +1609,14 @@ discard block |
||
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | 1611 | // *********************************************************************** |
| 1612 | - protected function _get_body($group, $id, $retries=3){ |
|
| 1612 | + protected function _get_body($group, $id, $retries = 3) { |
|
| 1613 | 1613 | /* |
| 1614 | 1614 | * Fetch the body of a given Message-ID taken from the headers |
| 1615 | 1615 | * The function then returns the raw content |
| 1616 | 1616 | */ |
| 1617 | 1617 | |
| 1618 | 1618 | $matches = NULL; |
| 1619 | - if(preg_match("/^\s*<(.*)>\s*$/", $id, $matches)) |
|
| 1619 | + if (preg_match("/^\s*<(.*)>\s*$/", $id, $matches)) |
|
| 1620 | 1620 | // Ensure we're always dealing with a properly |
| 1621 | 1621 | // formatted id |
| 1622 | 1622 | $id = $matches[1]; |
@@ -1625,16 +1625,16 @@ discard block |
||
| 1625 | 1625 | $raw = NULL; |
| 1626 | 1626 | do |
| 1627 | 1627 | { |
| 1628 | - $raw = $this->_nntp->getBody("<".$id.">", true); |
|
| 1628 | + $raw = $this->_nntp->getBody("<" . $id . ">", true); |
|
| 1629 | 1629 | // Retrieved Data |
| 1630 | 1630 | return $raw; |
| 1631 | - } while($retries > 0); |
|
| 1631 | + } while ($retries > 0); |
|
| 1632 | 1632 | // Fail |
| 1633 | 1633 | return false; |
| 1634 | 1634 | } |
| 1635 | 1635 | |
| 1636 | 1636 | // *********************************************************************** |
| 1637 | - protected function _get_headers($group, $range, $retries=3, $sort = true){ |
|
| 1637 | + protected function _get_headers($group, $range, $retries = 3, $sort = true) { |
|
| 1638 | 1638 | /* |
| 1639 | 1639 | * |
| 1640 | 1640 | * There is to much involved with fetching article headers |
@@ -1665,30 +1665,30 @@ discard block |
||
| 1665 | 1665 | // just report what it found.. (nothing). We do this because |
| 1666 | 1666 | // NNTP::isError() never threw, so the response has to be valid |
| 1667 | 1667 | // even though it's inconsistent |
| 1668 | - if(!$msgs)return []; |
|
| 1669 | - if(!is_array($msgs))return []; |
|
| 1668 | + if (!$msgs)return []; |
|
| 1669 | + if (!is_array($msgs))return []; |
|
| 1670 | 1670 | |
| 1671 | 1671 | // For whatever reason, we sometimes get an array of |
| 1672 | 1672 | // associative array returned, and all other times we just |
| 1673 | 1673 | // get an associative array. Convert the associative array |
| 1674 | 1674 | // if we get one to an array of associative array just to |
| 1675 | 1675 | // simplify the response and make it esier to work with |
| 1676 | - if((bool)count(array_filter(array_keys($msgs), 'is_string'))){ |
|
| 1676 | + if ((bool)count(array_filter(array_keys($msgs), 'is_string'))) { |
|
| 1677 | 1677 | // convert to an array of assocative array |
| 1678 | 1678 | $msgs = [$msgs]; |
| 1679 | 1679 | } |
| 1680 | 1680 | |
| 1681 | - for($i=0;$i<count($msgs);$i++){ |
|
| 1681 | + for ($i = 0; $i < count($msgs); $i++) { |
|
| 1682 | 1682 | $skip = false; |
| 1683 | - foreach($min_headers as $key){ |
|
| 1684 | - if(!array_key_exists($key, $msgs[$i])){ |
|
| 1683 | + foreach ($min_headers as $key) { |
|
| 1684 | + if (!array_key_exists($key, $msgs[$i])) { |
|
| 1685 | 1685 | unset($msgs[$i]); |
| 1686 | 1686 | $i--; |
| 1687 | 1687 | $skip = true; |
| 1688 | 1688 | break; |
| 1689 | 1689 | } |
| 1690 | 1690 | } |
| 1691 | - if($skip)continue; |
|
| 1691 | + if ($skip)continue; |
|
| 1692 | 1692 | |
| 1693 | 1693 | // Update Record With Epoch Value (# of sec from Jan, 1980) |
| 1694 | 1694 | $epoch[$i] = $msgs[$i]['Epoch'] = strtotime($msgs[$i]['Date']); |
@@ -1697,7 +1697,7 @@ discard block |
||
| 1697 | 1697 | $epoch[$i] = $msgs[$i]['Group'] = $group; |
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | - if($sort && count($msgs)>1) |
|
| 1700 | + if ($sort && count($msgs) > 1) |
|
| 1701 | 1701 | // Content is already sorted by articles, but if the |
| 1702 | 1702 | // sort flag is specified, then content is re-sorted by the |
| 1703 | 1703 | // messages stored epoch time |
@@ -1705,13 +1705,13 @@ discard block |
||
| 1705 | 1705 | |
| 1706 | 1706 | return $msgs; |
| 1707 | 1707 | |
| 1708 | - }while($retries >0); |
|
| 1708 | + } while ($retries > 0); |
|
| 1709 | 1709 | |
| 1710 | 1710 | return false; |
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | 1713 | // *********************************************************************** |
| 1714 | - public function post($reftime = NULL, $retries=3){ |
|
| 1714 | + public function post($reftime = NULL, $retries = 3) { |
|
| 1715 | 1715 | /* |
| 1716 | 1716 | * This function posts to usenet if there are any new updates |
| 1717 | 1717 | * to report that are flagged for transmit. |
@@ -1720,14 +1720,14 @@ discard block |
||
| 1720 | 1720 | */ |
| 1721 | 1721 | |
| 1722 | 1722 | // Make sure we can post |
| 1723 | - if(!$this->_can_post){ |
|
| 1723 | + if (!$this->_can_post) { |
|
| 1724 | 1724 | // Disabled |
| 1725 | 1725 | return false; |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | 1728 | $reftime_local = $reftime; |
| 1729 | 1729 | $article = NULL; |
| 1730 | - if($reftime_local === NULL){ |
|
| 1730 | + if ($reftime_local === NULL) { |
|
| 1731 | 1731 | // Fetch local time |
| 1732 | 1732 | $reftime_local = $this->utc2local(); |
| 1733 | 1733 | } |
@@ -1742,7 +1742,7 @@ discard block |
||
| 1742 | 1742 | ]; |
| 1743 | 1743 | |
| 1744 | 1744 | // Store Comments |
| 1745 | - while(($data = $this->unPostedComments()) !== NULL) |
|
| 1745 | + while (($data = $this->unPostedComments()) !== NULL) |
|
| 1746 | 1746 | { |
| 1747 | 1747 | $message['comments'] = $data['comments']; |
| 1748 | 1748 | $sql = sprintf("UPDATE release_comments " |
@@ -1750,9 +1750,9 @@ discard block |
||
| 1750 | 1750 | implode(",", $data['ids'])); |
| 1751 | 1751 | |
| 1752 | 1752 | // Generate keys if one doesn't exist |
| 1753 | - if(!($this->_ssl_prvkey && $this->_ssl_pubkey)) |
|
| 1753 | + if (!($this->_ssl_prvkey && $this->_ssl_pubkey)) |
|
| 1754 | 1754 | { |
| 1755 | - if($this->keygen(false, true) !== false) |
|
| 1755 | + if ($this->keygen(false, true) !== false) |
|
| 1756 | 1756 | // Post a discovery message if enabled |
| 1757 | 1757 | $this->post_discovery(); |
| 1758 | 1758 | else |
@@ -1761,7 +1761,7 @@ discard block |
||
| 1761 | 1761 | |
| 1762 | 1762 | // Encode Message so it can be posted |
| 1763 | 1763 | $article = $this->encodePost($message, $reftime_local); |
| 1764 | - if($article === false){ |
|
| 1764 | + if ($article === false) { |
|
| 1765 | 1765 | echo "Failed.\n"; |
| 1766 | 1766 | return false; |
| 1767 | 1767 | } |
@@ -1786,10 +1786,10 @@ discard block |
||
| 1786 | 1786 | } |
| 1787 | 1787 | |
| 1788 | 1788 | // *********************************************************************** |
| 1789 | - private function _postArticle ($article, $retries=3) |
|
| 1789 | + private function _postArticle($article, $retries = 3) |
|
| 1790 | 1790 | { |
| 1791 | 1791 | // Extract message id |
| 1792 | - if(!preg_match('/Message-ID: <(?P<id>[^>]+)>/', $article[0], $matches)){ |
|
| 1792 | + if (!preg_match('/Message-ID: <(?P<id>[^>]+)>/', $article[0], $matches)) { |
|
| 1793 | 1793 | // we couldn't extract the message id |
| 1794 | 1794 | return false; |
| 1795 | 1795 | } |
@@ -1800,12 +1800,12 @@ discard block |
||
| 1800 | 1800 | if (($this->_pdo->getSetting('alternate_nntp') == 1 ? $this->_nntp->doConnect(true, true) : $this->_nntp->doConnect()) !== true) { |
| 1801 | 1801 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 1802 | 1802 | } |
| 1803 | - while($retries > 0) |
|
| 1803 | + while ($retries > 0) |
|
| 1804 | 1804 | { |
| 1805 | 1805 | try |
| 1806 | 1806 | { |
| 1807 | 1807 | $summary = $this->_nntp->selectGroup($this->_post_group); |
| 1808 | - if(NNTP::isError($summary)){ |
|
| 1808 | + if (NNTP::isError($summary)) { |
|
| 1809 | 1809 | $summary = $this->_nntpReset($this->_post_group); |
| 1810 | 1810 | $retries--; |
| 1811 | 1811 | continue; |
@@ -1821,10 +1821,10 @@ discard block |
||
| 1821 | 1821 | // Actually send the article |
| 1822 | 1822 | $_err = $this->_nntp->cmdPost2($article); |
| 1823 | 1823 | |
| 1824 | - }catch(\Exception $e){ |
|
| 1824 | + } catch (\Exception $e) { |
|
| 1825 | 1825 | // Ensure We're not connected |
| 1826 | - try{$this->_nntp->doQuit();} |
|
| 1827 | - catch(\Exception $e) |
|
| 1826 | + try {$this->_nntp->doQuit(); } |
|
| 1827 | + catch (\Exception $e) |
|
| 1828 | 1828 | {/* do nothing */} |
| 1829 | 1829 | |
| 1830 | 1830 | // Post failed |
@@ -1847,11 +1847,11 @@ discard block |
||
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | 1849 | // *********************************************************************** |
| 1850 | - private function _nntpReset ($group = NULL) |
|
| 1850 | + private function _nntpReset($group = NULL) |
|
| 1851 | 1851 | { |
| 1852 | 1852 | // Reset Connection |
| 1853 | - try{$this->_nntp->doQuit();} |
|
| 1854 | - catch(\Exception $e) |
|
| 1853 | + try {$this->_nntp->doQuit(); } |
|
| 1854 | + catch (\Exception $e) |
|
| 1855 | 1855 | {/* do nothing */} |
| 1856 | 1856 | |
| 1857 | 1857 | // Attempt to reconnect |
@@ -1859,7 +1859,7 @@ discard block |
||
| 1859 | 1859 | exit($this->_pdo->log->error("Unable to connect to usenet." . PHP_EOL)); |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | - if($group !== NULL) |
|
| 1862 | + if ($group !== NULL) |
|
| 1863 | 1863 | { |
| 1864 | 1864 | // Reselect group if specified |
| 1865 | 1865 | $summary = $this->_nntp->selectGroup($this->_post_group); |
@@ -1874,7 +1874,7 @@ discard block |
||
| 1874 | 1874 | static $vc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
| 1875 | 1875 | |
| 1876 | 1876 | $unique = ''; |
| 1877 | - for($i = 0; $i < $len; $i++) |
|
| 1877 | + for ($i = 0; $i < $len; $i++) |
|
| 1878 | 1878 | $unique .= $vc[mt_rand(0, strlen($vc) - 1)]; |
| 1879 | 1879 | |
| 1880 | 1880 | return $unique; |
@@ -1893,23 +1893,23 @@ discard block |
||
| 1893 | 1893 | $key = $this->_ssl_pubkey; |
| 1894 | 1894 | |
| 1895 | 1895 | // Decrypt Message |
| 1896 | - if($decrypt){ |
|
| 1896 | + if ($decrypt) { |
|
| 1897 | 1897 | $message = $this->decrypt($message, $key); |
| 1898 | - if($message === false){ |
|
| 1898 | + if ($message === false) { |
|
| 1899 | 1899 | // fail |
| 1900 | 1900 | return false; |
| 1901 | 1901 | } |
| 1902 | - }else{ |
|
| 1902 | + } else { |
|
| 1903 | 1903 | // Convert from base64 |
| 1904 | 1904 | $message = base64_decode($message); |
| 1905 | - if($message === false){ |
|
| 1905 | + if ($message === false) { |
|
| 1906 | 1906 | // Fail |
| 1907 | 1907 | return false; |
| 1908 | 1908 | } |
| 1909 | 1909 | } |
| 1910 | 1910 | |
| 1911 | 1911 | $message = json_decode($message, true); |
| 1912 | - if($message === false){ |
|
| 1912 | + if ($message === false) { |
|
| 1913 | 1913 | // Fail |
| 1914 | 1914 | return false; |
| 1915 | 1915 | } |
@@ -1948,13 +1948,13 @@ discard block |
||
| 1948 | 1948 | SpotNab::SEGID_DOMAIN |
| 1949 | 1949 | ); |
| 1950 | 1950 | |
| 1951 | - if(!is_string($message)){ |
|
| 1951 | + if (!is_string($message)) { |
|
| 1952 | 1952 | // If message is not already in string format, then |
| 1953 | 1953 | // it's in it's assembled mixed array format... we |
| 1954 | 1954 | // need to convert it to json before proceeding |
| 1955 | - $message = json_encode($message, JSON_HEX_TAG|JSON_HEX_APOS| |
|
| 1956 | - JSON_HEX_QUOT|JSON_HEX_AMP|JSON_UNESCAPED_UNICODE); |
|
| 1957 | - if($message === false){ |
|
| 1955 | + $message = json_encode($message, JSON_HEX_TAG | JSON_HEX_APOS | |
|
| 1956 | + JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE); |
|
| 1957 | + if ($message === false) { |
|
| 1958 | 1958 | // Fail |
| 1959 | 1959 | return false; |
| 1960 | 1960 | } |
@@ -1966,14 +1966,14 @@ discard block |
||
| 1966 | 1966 | // [1] => 'Message Body' |
| 1967 | 1967 | // ); |
| 1968 | 1968 | |
| 1969 | - if($encrypt){ |
|
| 1969 | + if ($encrypt) { |
|
| 1970 | 1970 | // Encrypt Message |
| 1971 | 1971 | $message = $this->encrypt($message, $prvkey, $passphrase); |
| 1972 | - if($message === false){ |
|
| 1972 | + if ($message === false) { |
|
| 1973 | 1973 | // fail |
| 1974 | 1974 | return false; |
| 1975 | 1975 | } |
| 1976 | - }else{ |
|
| 1976 | + } else { |
|
| 1977 | 1977 | // Convert to base64 |
| 1978 | 1978 | $message = base64_encode($message); |
| 1979 | 1979 | } |
@@ -1999,11 +1999,11 @@ discard block |
||
| 1999 | 1999 | $reftime |
| 2000 | 2000 | ); |
| 2001 | 2001 | |
| 2002 | - if($user === NULL) |
|
| 2002 | + if ($user === NULL) |
|
| 2003 | 2003 | $user = trim($this->_post_user); |
| 2004 | - if($email === NULL) |
|
| 2004 | + if ($email === NULL) |
|
| 2005 | 2005 | $email = trim($this->_post_email); |
| 2006 | - if($group === NULL) |
|
| 2006 | + if ($group === NULL) |
|
| 2007 | 2007 | $group = trim($this->_post_group); |
| 2008 | 2008 | |
| 2009 | 2009 | $header = "Subject: " . $subject . "\r\n"; |
@@ -2012,7 +2012,7 @@ discard block |
||
| 2012 | 2012 | $header .= "X-Newsreader: NewzNab v 0.4.1" . "\r\n"; |
| 2013 | 2013 | $header .= "X-No-Archive: yes\r\n"; |
| 2014 | 2014 | |
| 2015 | - $header .= "From: ".$user. " <" . $email . ">\r\n"; |
|
| 2015 | + $header .= "From: " . $user . " <" . $email . ">\r\n"; |
|
| 2016 | 2016 | |
| 2017 | 2017 | // Binary Content |
| 2018 | 2018 | $header .= 'Content-Type: text/plain; charset=ISO-8859-1' . "\r\n"; |
@@ -2021,7 +2021,7 @@ discard block |
||
| 2021 | 2021 | // Assemble Article in structure NNTP expects |
| 2022 | 2022 | $article = [$header, $message]; |
| 2023 | 2023 | |
| 2024 | - if($debug){ |
|
| 2024 | + if ($debug) { |
|
| 2025 | 2025 | // Append some debug data to the article |
| 2026 | 2026 | $article[] = [ |
| 2027 | 2027 | 'Number' => 1234, |
@@ -2060,32 +2060,32 @@ discard block |
||
| 2060 | 2060 | ."LIMIT %d", $limit); |
| 2061 | 2061 | |
| 2062 | 2062 | $res = $this->_pdo->query($sql); |
| 2063 | - if(!$res) |
|
| 2063 | + if (!$res) |
|
| 2064 | 2064 | return NULL; |
| 2065 | 2065 | |
| 2066 | 2066 | // Now we prepare a comments array to return with |
| 2067 | 2067 | $comments = []; |
| 2068 | 2068 | $ids = []; |
| 2069 | 2069 | |
| 2070 | - foreach($res as $comment){ |
|
| 2070 | + foreach ($res as $comment) { |
|
| 2071 | 2071 | // If we don't have a gid then we can't make the post; |
| 2072 | 2072 | // the user hasn't set up there database to store the gid's |
| 2073 | 2073 | // correctly |
| 2074 | 2074 | |
| 2075 | - if(empty($comment['gid'])) |
|
| 2075 | + if (empty($comment['gid'])) |
|
| 2076 | 2076 | continue; |
| 2077 | 2077 | |
| 2078 | 2078 | // Privacy options (scramble username or not) |
| 2079 | 2079 | if ($this->_post_privacy) |
| 2080 | 2080 | $username = sprintf( |
| 2081 | 2081 | "sn-%s", |
| 2082 | - substr(md5($comment['username'].$this->_pdo->getSetting('siteseed')), 0, 6) |
|
| 2082 | + substr(md5($comment['username'] . $this->_pdo->getSetting('siteseed')), 0, 6) |
|
| 2083 | 2083 | ); |
| 2084 | 2084 | else |
| 2085 | 2085 | $username = $comment['username']; |
| 2086 | 2086 | |
| 2087 | 2087 | // Hash a unique Comment id to associate with this message |
| 2088 | - $cid = md5($comment['id'].$comment['username'].$comment['createddate'].$comment['host']); |
|
| 2088 | + $cid = md5($comment['id'] . $comment['username'] . $comment['createddate'] . $comment['host']); |
|
| 2089 | 2089 | |
| 2090 | 2090 | // Keep list of IDs (required for cleanup) |
| 2091 | 2091 | $ids[] = $comment['id']; |
@@ -2108,45 +2108,45 @@ discard block |
||
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | 2110 | // Return Results if they are present |
| 2111 | - return (count($comments)>0)? |
|
| 2112 | - ['comments' => $comments, 'ids' => $ids] :NULL; |
|
| 2111 | + return (count($comments) > 0) ? |
|
| 2112 | + ['comments' => $comments, 'ids' => $ids] : NULL; |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | // *********************************************************************** |
| 2116 | - public function utc2local($utc = NULL, $format="Y-m-d H:i:s") { |
|
| 2116 | + public function utc2local($utc = NULL, $format = "Y-m-d H:i:s") { |
|
| 2117 | 2117 | /* |
| 2118 | 2118 | * Takes a utc time as input and outputs local |
| 2119 | 2119 | * If no argument is specified then current local |
| 2120 | 2120 | * time is returned. |
| 2121 | 2121 | */ |
| 2122 | - if(is_string($utc)) { |
|
| 2123 | - return date($format, strtotime($utc. " UTC")); |
|
| 2124 | - } else if(is_int($utc)) { |
|
| 2125 | - return date($format, strtotime(date($format, $utc)." UTC")); |
|
| 2122 | + if (is_string($utc)) { |
|
| 2123 | + return date($format, strtotime($utc . " UTC")); |
|
| 2124 | + } else if (is_int($utc)) { |
|
| 2125 | + return date($format, strtotime(date($format, $utc) . " UTC")); |
|
| 2126 | 2126 | } |
| 2127 | 2127 | return date($format); |
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | 2130 | // *********************************************************************** |
| 2131 | - public function local2utc($local = NULL, $format="Y-m-d H:i:s") { |
|
| 2131 | + public function local2utc($local = NULL, $format = "Y-m-d H:i:s") { |
|
| 2132 | 2132 | /* |
| 2133 | 2133 | * Takes a local time as input and outputs UTC |
| 2134 | 2134 | * If no argument is specified then current UTC |
| 2135 | 2135 | * time is returned. |
| 2136 | 2136 | */ |
| 2137 | - if(is_string($local)) { |
|
| 2137 | + if (is_string($local)) { |
|
| 2138 | 2138 | return gmdate($format, strtotime($local)); |
| 2139 | - } else if(is_int($local)) { |
|
| 2139 | + } else if (is_int($local)) { |
|
| 2140 | 2140 | return gmdate($format, $local); |
| 2141 | 2141 | } |
| 2142 | 2142 | return gmdate($format); |
| 2143 | 2143 | } |
| 2144 | 2144 | |
| 2145 | 2145 | // *********************************************************************** |
| 2146 | - private function _keygen($passphrase = NULL, $bits=1024, |
|
| 2147 | - $type=OPENSSL_KEYTYPE_RSA) |
|
| 2146 | + private function _keygen($passphrase = NULL, $bits = 1024, |
|
| 2147 | + $type = OPENSSL_KEYTYPE_RSA) |
|
| 2148 | 2148 | { |
| 2149 | - if(!function_exists('openssl_pkey_new')) { |
|
| 2149 | + if (!function_exists('openssl_pkey_new')) { |
|
| 2150 | 2150 | return false; |
| 2151 | 2151 | } |
| 2152 | 2152 | |
@@ -2171,7 +2171,7 @@ discard block |
||
| 2171 | 2171 | |
| 2172 | 2172 | // Get Public Key |
| 2173 | 2173 | $details = openssl_pkey_get_details($res); |
| 2174 | - if($details === false) { |
|
| 2174 | + if ($details === false) { |
|
| 2175 | 2175 | return false; |
| 2176 | 2176 | } |
| 2177 | 2177 | $pubkey = $details['key']; |
@@ -2183,23 +2183,23 @@ discard block |
||
| 2183 | 2183 | } |
| 2184 | 2184 | |
| 2185 | 2185 | // *********************************************************************** |
| 2186 | - public function encrypt ($source, $prvkey = NULL, $passphrase = NULL){ |
|
| 2186 | + public function encrypt($source, $prvkey = NULL, $passphrase = NULL) { |
|
| 2187 | 2187 | // Encryption performed using private key |
| 2188 | - if($prvkey === NULL) |
|
| 2188 | + if ($prvkey === NULL) |
|
| 2189 | 2189 | // Default Key if none is specified |
| 2190 | 2190 | $prvkey = $this->_ssl_prvkey; |
| 2191 | 2191 | |
| 2192 | - if(!$prvkey) |
|
| 2192 | + if (!$prvkey) |
|
| 2193 | 2193 | // Still no key... |
| 2194 | 2194 | return false; |
| 2195 | 2195 | |
| 2196 | - if(!function_exists('openssl_get_privatekey')) |
|
| 2196 | + if (!function_exists('openssl_get_privatekey')) |
|
| 2197 | 2197 | return false; |
| 2198 | 2198 | |
| 2199 | 2199 | // Load Public Key into array |
| 2200 | - $crypttext=''; |
|
| 2200 | + $crypttext = ''; |
|
| 2201 | 2201 | $pkey = openssl_get_privatekey($prvkey, $passphrase); |
| 2202 | - if($pkey === false) |
|
| 2202 | + if ($pkey === false) |
|
| 2203 | 2203 | // bad key |
| 2204 | 2204 | return false; |
| 2205 | 2205 | |
@@ -2207,17 +2207,17 @@ discard block |
||
| 2207 | 2207 | $ptr = 0; |
| 2208 | 2208 | $encrypted = ''; |
| 2209 | 2209 | |
| 2210 | - while($len > 0){ |
|
| 2210 | + while ($len > 0) { |
|
| 2211 | 2211 | // Prepare batch size |
| 2212 | 2212 | $batch = (($len - SpotNab::SSL_MAX_BUF_LEN) > 0) ? SpotNab::SSL_MAX_BUF_LEN : $len; |
| 2213 | 2213 | |
| 2214 | 2214 | $res = openssl_private_encrypt(substr($source, $ptr, $batch), $crypttext, $pkey); |
| 2215 | - if($res === false) { |
|
| 2215 | + if ($res === false) { |
|
| 2216 | 2216 | // Encryption failed |
| 2217 | 2217 | openssl_free_key($pkey); |
| 2218 | 2218 | return false; |
| 2219 | 2219 | } |
| 2220 | - $encrypted .= base64_encode($crypttext) . SpotNab::SSL_BUF_DELIMITER; |
|
| 2220 | + $encrypted .= base64_encode($crypttext) . SpotNab::SSL_BUF_DELIMITER; |
|
| 2221 | 2221 | $len -= $batch; |
| 2222 | 2222 | $ptr += $batch; |
| 2223 | 2223 | } |
@@ -2226,21 +2226,21 @@ discard block |
||
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | // *********************************************************************** |
| 2229 | - public function decrypt ($source, $pubkey = NULL){ |
|
| 2229 | + public function decrypt($source, $pubkey = NULL) { |
|
| 2230 | 2230 | // Decryption performed using public key |
| 2231 | - if($pubkey === NULL) |
|
| 2231 | + if ($pubkey === NULL) |
|
| 2232 | 2232 | // Default Key if none is specified |
| 2233 | 2233 | $pubkey = $this->_ssl_pubkey; |
| 2234 | 2234 | |
| 2235 | - if(!$pubkey) |
|
| 2235 | + if (!$pubkey) |
|
| 2236 | 2236 | // Still no key... |
| 2237 | 2237 | return false; |
| 2238 | 2238 | |
| 2239 | - if(!function_exists('openssl_get_publickey')) |
|
| 2239 | + if (!function_exists('openssl_get_publickey')) |
|
| 2240 | 2240 | return false; |
| 2241 | 2241 | |
| 2242 | 2242 | $pkey = openssl_get_publickey($pubkey); |
| 2243 | - if($pkey === false){ |
|
| 2243 | + if ($pkey === false) { |
|
| 2244 | 2244 | // bad key |
| 2245 | 2245 | //echo openssl_error_string(); |
| 2246 | 2246 | return false; |
@@ -2249,16 +2249,16 @@ discard block |
||
| 2249 | 2249 | $cryptlist = explode(SpotNab::SSL_BUF_DELIMITER, $source); |
| 2250 | 2250 | |
| 2251 | 2251 | $decrypted = ''; |
| 2252 | - foreach($cryptlist as $crypt){ |
|
| 2253 | - if(!strlen($crypt))break; |
|
| 2252 | + foreach ($cryptlist as $crypt) { |
|
| 2253 | + if (!strlen($crypt))break; |
|
| 2254 | 2254 | $_crypt = base64_decode($crypt); |
| 2255 | - if($_crypt === false){ |
|
| 2255 | + if ($_crypt === false) { |
|
| 2256 | 2256 | // Fail |
| 2257 | 2257 | return false; |
| 2258 | 2258 | } |
| 2259 | 2259 | |
| 2260 | 2260 | $res = openssl_public_decrypt($_crypt, $out, $pkey, OPENSSL_PKCS1_PADDING); |
| 2261 | - if($res === false){ |
|
| 2261 | + if ($res === false) { |
|
| 2262 | 2262 | // Decryption failed |
| 2263 | 2263 | //echo "DEBUG: ".openssl_error_string()."\n"; |
| 2264 | 2264 | openssl_free_key($pkey); |
@@ -2272,7 +2272,7 @@ discard block |
||
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | 2274 | // *********************************************************************** |
| 2275 | - public function compstr ($str){ |
|
| 2275 | + public function compstr($str) { |
|
| 2276 | 2276 | /* |
| 2277 | 2277 | * Compress a string |
| 2278 | 2278 | */ |
@@ -2281,7 +2281,7 @@ discard block |
||
| 2281 | 2281 | } |
| 2282 | 2282 | |
| 2283 | 2283 | // *********************************************************************** |
| 2284 | - public function decompstr ($str){ |
|
| 2284 | + public function decompstr($str) { |
|
| 2285 | 2285 | /* |
| 2286 | 2286 | * De-compress a string |
| 2287 | 2287 | */ |
@@ -2302,7 +2302,7 @@ discard block |
||
| 2302 | 2302 | return $this->_pdo->queryOneRow($sql); |
| 2303 | 2303 | } |
| 2304 | 2304 | |
| 2305 | - public function addSource($description,$username,$usermail,$usenetgroup,$publickey) |
|
| 2305 | + public function addSource($description, $username, $usermail, $usenetgroup, $publickey) |
|
| 2306 | 2306 | { |
| 2307 | 2307 | $sql = sprintf("INSERT INTO spotnabsources " |
| 2308 | 2308 | ."(description, username, useremail," |
@@ -2314,7 +2314,7 @@ discard block |
||
| 2314 | 2314 | return $this->_pdo->queryInsert($sql); |
| 2315 | 2315 | } |
| 2316 | 2316 | |
| 2317 | - public function updateSource($id, $description,$username,$usermail,$usenetgroup,$publickey) |
|
| 2317 | + public function updateSource($id, $description, $username, $usermail, $usenetgroup, $publickey) |
|
| 2318 | 2318 | { |
| 2319 | 2319 | return $this->_pdo->queryExec( |
| 2320 | 2320 | sprintf("UPDATE spotnabsources SET " |
@@ -2335,7 +2335,7 @@ discard block |
||
| 2335 | 2335 | return $this->_pdo->queryExec(sprintf("update spotnabsources SET active = %d WHERE id = %d", $active, $id)); |
| 2336 | 2336 | } |
| 2337 | 2337 | |
| 2338 | - public function getDefaultValue($table,$field) |
|
| 2338 | + public function getDefaultValue($table, $field) |
|
| 2339 | 2339 | { |
| 2340 | 2340 | return $this->_pdo->query(sprintf("SHOW COLUMNS FROM %s WHERE field = %s", $table, $this->_pdo->escapeString($field))); |
| 2341 | 2341 | } |