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