diff --git a/lib/DB/mysqldump_tables.php b/lib/DB/mysqldump_tables.php index b90073d6d..2c429b82e 100644 --- a/lib/DB/mysqldump_tables.php +++ b/lib/DB/mysqldump_tables.php @@ -1,5 +1,5 @@ 0) { function newname($filename) { - rename($filename, dirname($filename)."/".basename($filename,".gz")."_".date("Y_m_d_His", filemtime($filename)).".gz"); + rename($filename, dirname($filename) . "/" . basename($filename, ".gz") . "_" . date("Y_m_d_His", filemtime($filename)) . ".gz"); } function builddefaultsfile() @@ -41,7 +41,7 @@ function builddefaultsfile() ."password = " . DB_PASSWORD; $filehandle = fopen("mysql-defaults.txt", "w+"); - if(!$filehandle) { + if (!$filehandle) { exit("Unable to write mysql defaults file! Exiting"); } else { fwrite($filehandle, $filetext); @@ -66,16 +66,16 @@ if (DB_SOCKET != '') { //generate defaults file used to store database login information so it is not in cleartext in ps command for mysqldump builddefaultsfile(); -if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) { - $filename = $argv[3]."/".$dbname.".gz"; +if ((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) { + $filename = $argv[3] . "/" . $dbname . ".gz"; echo $pdo->log->header("Dumping $dbname."); if (file_exists($filename)) { newname($filename); } - $command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname | gzip -9 > $filename"; + $command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use " . "$dbname | gzip -9 > $filename"; system($command); -} else if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) { - $filename = $argv[3]."/".$dbname.".gz"; +} else if ((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) { + $filename = $argv[3] . "/" . $dbname . ".gz"; if (file_exists($filename)) { echo $pdo->log->header("Restoring $dbname."); $command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname"; @@ -83,26 +83,26 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum system($command); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1"); } -} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) { +} else if ((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) { $sql = "SHOW tables"; $tables = $pdo->query($sql); - foreach($tables as $row) { - $tbl = $row['tables_in_'.DB_NAME]; - $filename = $argv[3]."/".$tbl.".gz"; + foreach ($tables as $row) { + $tbl = $row['tables_in_' . DB_NAME]; + $filename = $argv[3] . "/" . $tbl . ".gz"; echo $pdo->log->header("Dumping $tbl."); if (file_exists($filename)) { newname($filename); } - $command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname $tbl | gzip -9 > $filename"; + $command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use " . "$dbname $tbl | gzip -9 > $filename"; system($command); } -} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) { +} else if ((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) { $sql = "SHOW tables"; $tables = $pdo->query($sql); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0"); - foreach($tables as $row) { - $tbl = $row['tables_in_'.DB_NAME]; - $filename = $argv[3]."/".$tbl.".gz"; + foreach ($tables as $row) { + $tbl = $row['tables_in_' . DB_NAME]; + $filename = $argv[3] . "/" . $tbl . ".gz"; if (file_exists($filename)) { echo $pdo->log->header("Restoring $tbl."); $command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname"; @@ -110,22 +110,22 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum } } $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1"); -} else if((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) { +} else if ((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) { $arr = array("parts", "binaries", "partrepair", "groups"); foreach ($arr as &$tbl) { - $filename = $argv[3]."/".$tbl.".gz"; + $filename = $argv[3] . "/" . $tbl . ".gz"; echo $pdo->log->header("Dumping $tbl.."); if (file_exists($filename)) { newname($filename); } - $command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname $tbl | gzip -9 > $filename"; + $command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use " . "$dbname $tbl | gzip -9 > $filename"; system($command); } -} else if((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) { +} else if ((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) { $arr = array("parts", "binaries", "partrepair", "groups"); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0"); foreach ($arr as &$tbl) { - $filename = $argv[3]."/".$tbl.".gz"; + $filename = $argv[3] . "/" . $tbl . ".gz"; if (file_exists($filename)) { echo $pdo->log->header("Restoring $tbl."); $command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname"; @@ -133,25 +133,25 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum } } $pdo->queryExec("SET FOREIGN_KEY_CHECKS=1"); -} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "outfile") && (isset($argv[3]) && file_exists($argv[3]))) { +} else if ((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "outfile") && (isset($argv[3]) && file_exists($argv[3]))) { $sql = "SHOW tables"; $tables = $pdo->query($sql); - foreach($tables as $row) { - $tbl = $row['tables_in_'.DB_NAME]; - $filename = $argv[3].$tbl.".csv"; + foreach ($tables as $row) { + $tbl = $row['tables_in_' . DB_NAME]; + $filename = $argv[3] . $tbl . ".csv"; echo $pdo->log->header("Dumping $tbl."); if (file_exists($filename)) { newname($filename); } $pdo->queryDirect(sprintf("SELECT * INTO OUTFILE %s FROM %s", $pdo->escapeString($filename), $tbl)); } -} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "infile") && (isset($argv[3]) && is_dir($argv[3]))) { +} else if ((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "infile") && (isset($argv[3]) && is_dir($argv[3]))) { $sql = "SHOW tables"; $tables = $pdo->query($sql); $pdo->queryExec("SET FOREIGN_KEY_CHECKS=0"); - foreach($tables as $row) { - $tbl = $row['tables_in_'.DB_NAME]; - $filename = $argv[3].$tbl.".csv"; + foreach ($tables as $row) { + $tbl = $row['tables_in_' . DB_NAME]; + $filename = $argv[3] . $tbl . ".csv"; if (file_exists($filename)) { echo $pdo->log->header("Restoring $tbl."); $pdo->queryExec(sprintf("LOAD DATA INFILE %s INTO TABLE %s", $pdo->escapeString($filename), $tbl)); @@ -176,6 +176,6 @@ if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dum . "php $argv[0] all infile /path/to/restore/from ...: To restore all tables, using INFILE.\n\n"); } -if(file_exists("mysql-defaults.txt")) { +if (file_exists("mysql-defaults.txt")) { @unlink("mysql-defaults.txt"); } \ No newline at end of file diff --git a/lib/DB/patchDB.php b/lib/DB/patchDB.php index aa625e9b7..381d1a901 100644 --- a/lib/DB/patchDB.php +++ b/lib/DB/patchDB.php @@ -1,11 +1,11 @@ pdo->queryExec( @@ -467,16 +466,16 @@ class Film UPDATE movieinfo SET %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, updateddate = NOW() WHERE imdbid = %d", - (empty($title) ? '' : 'title = ' . $this->pdo->escapeString($title)), - (empty($tagLine) ? '' : 'tagline = ' . $this->pdo->escapeString($tagLine)), - (empty($plot) ? '' : 'plot = ' . $this->pdo->escapeString($plot)), - (empty($year) ? '' : 'year = ' . $this->pdo->escapeString($year)), - (empty($rating) ? '' : 'rating = ' . $this->pdo->escapeString($rating)), - (empty($genre) ? '' : 'genre = ' . $this->pdo->escapeString($genre)), + (empty($title) ? '' : 'title = ' . $this->pdo->escapeString($title)), + (empty($tagLine) ? '' : 'tagline = ' . $this->pdo->escapeString($tagLine)), + (empty($plot) ? '' : 'plot = ' . $this->pdo->escapeString($plot)), + (empty($year) ? '' : 'year = ' . $this->pdo->escapeString($year)), + (empty($rating) ? '' : 'rating = ' . $this->pdo->escapeString($rating)), + (empty($genre) ? '' : 'genre = ' . $this->pdo->escapeString($genre)), (empty($director) ? '' : 'director = ' . $this->pdo->escapeString($director)), - (empty($actors) ? '' : 'actors = ' . $this->pdo->escapeString($actors)), + (empty($actors) ? '' : 'actors = ' . $this->pdo->escapeString($actors)), (empty($language) ? '' : 'language = ' . $this->pdo->escapeString($language)), - (empty($cover) ? '' : 'cover = ' . $cover), + (empty($cover) ? '' : 'cover = ' . $cover), (empty($backdrop) ? '' : 'backdrop = ' . $backdrop), $id ) @@ -489,7 +488,7 @@ class Film * * @param $variable * - * @return string + * @return boolean */ protected function checkVariable(&$variable) { @@ -520,7 +519,7 @@ class Film /** * Fetch IMDB/TMDB info for the movie. * - * @param $imdbId + * @param string $imdbId * * @return bool */ @@ -571,12 +570,12 @@ class Film $mov['banner'] = $this->releaseImage->saveImage($imdbId . '-banner', $fanart['banner'], $this->imgSavePath); } - $mov['title'] = $this->setTmdbImdbVar($imdb['title'] , $tmdb['title']); - $mov['rating'] = $this->setTmdbImdbVar($imdb['rating'] , $tmdb['rating']); - $mov['plot'] = $this->setTmdbImdbVar($imdb['plot'] , $tmdb['plot']); + $mov['title'] = $this->setTmdbImdbVar($imdb['title'], $tmdb['title']); + $mov['rating'] = $this->setTmdbImdbVar($imdb['rating'], $tmdb['rating']); + $mov['plot'] = $this->setTmdbImdbVar($imdb['plot'], $tmdb['plot']); $mov['tagline'] = $this->setTmdbImdbVar($imdb['tagline'], $tmdb['tagline']); - $mov['year'] = $this->setTmdbImdbVar($imdb['year'] , $tmdb['year']); - $mov['genre'] = $this->setTmdbImdbVar($imdb['genre'] , $tmdb['genre']); + $mov['year'] = $this->setTmdbImdbVar($imdb['year'], $tmdb['year']); + $mov['genre'] = $this->setTmdbImdbVar($imdb['genre'], $tmdb['genre']); if ($this->checkVariable($imdb['type'])) { $mov['type'] = $imdb['type']; @@ -602,15 +601,15 @@ class Film $mov['type'] = implode(', ', array_unique($mov['type'])); } - $mov['title'] = html_entity_decode($mov['title'] , ENT_QUOTES, 'UTF-8'); + $mov['title'] = html_entity_decode($mov['title'], ENT_QUOTES, 'UTF-8'); $mov['plot'] = html_entity_decode(preg_replace('/\s+See full summary ยป/', ' ', $mov['plot']), ENT_QUOTES, 'UTF-8'); - $mov['tagline'] = html_entity_decode($mov['tagline'] , ENT_QUOTES, 'UTF-8'); - $mov['genre'] = html_entity_decode($mov['genre'] , ENT_QUOTES, 'UTF-8'); + $mov['tagline'] = html_entity_decode($mov['tagline'], ENT_QUOTES, 'UTF-8'); + $mov['genre'] = html_entity_decode($mov['genre'], ENT_QUOTES, 'UTF-8'); $mov['director'] = html_entity_decode($mov['director'], ENT_QUOTES, 'UTF-8'); - $mov['actors'] = html_entity_decode($mov['actors'] , ENT_QUOTES, 'UTF-8'); + $mov['actors'] = html_entity_decode($mov['actors'], ENT_QUOTES, 'UTF-8'); $mov['language'] = html_entity_decode($mov['language'], ENT_QUOTES, 'UTF-8'); - $mov['type'] = html_entity_decode(ucwords(preg_replace('/[\.\_]/', ' ', $mov['type'])), ENT_QUOTES, 'UTF-8'); + $mov['type'] = html_entity_decode(ucwords(preg_replace('/[\.\_]/', ' ', $mov['type'])), ENT_QUOTES, 'UTF-8'); $mov['title'] = str_replace(array('/', '\\'), '', $mov['title']); $movieID = $this->pdo->queryInsert( @@ -682,7 +681,7 @@ class Film { if ($this->fanartapikey != '') { - $buffer = Utility::getUrl(['url' => 'https://webservice.fanart.tv/v3/movies/' . 'tt' . $imdbId . '?api_key=' . $this->fanartapikey , 'verifycert' => false]); + $buffer = Utility::getUrl(['url' => 'https://webservice.fanart.tv/v3/movies/' . 'tt' . $imdbId . '?api_key=' . $this->fanartapikey, 'verifycert' => false]); if ($buffer !== false) { $art = json_decode($buffer, true); if (isset($art['status']) && $art['status'] === 'error') { @@ -1049,8 +1048,8 @@ class Film //If we found a year, try looking in a 4 year range. if ($this->currentYear !== false) { - $start = (int) $this->currentYear - 2; - $end = (int) $this->currentYear + 2; + $start = (int)$this->currentYear - 2; + $end = (int)$this->currentYear + 2; $andYearIn = 'AND year IN ('; while ($start < $end) { $andYearIn .= $start . ','; @@ -1148,7 +1147,7 @@ class Film */ protected function googleSearch() { - $buffer =Utility::getUrl([ + $buffer = Utility::getUrl([ 'url' => 'https://www.google.com/search?hl=en&as_q=&as_epq=' . urlencode( @@ -1352,6 +1351,9 @@ class Film } } + /** + * @param RottenTomato $rt + */ protected function _getRTData($operation = '', $rt) { $count = 0; @@ -1416,7 +1418,7 @@ class Film /** * Update upcoming table. * - * @param $source + * @param string $source * @param $type * @param $info * @@ -1440,7 +1442,7 @@ class Film /** * Get IMDB genres. * - * @return array + * @return string[] */ public function getGenres() { diff --git a/lib/IRCScraper.php b/lib/IRCScraper.php index 6cda5d4c1..b7d87d946 100644 --- a/lib/IRCScraper.php +++ b/lib/IRCScraper.php @@ -215,7 +215,7 @@ class IRCScraper extends IRCClient } if ($matches['req'] !== 'N/A' && preg_match('/^(?P\d+):(?P.+)$/i', $matches['req'], $matches2)) { $this->_curPre['reqid'] = $matches2['req']; - $this->_curPre['group_id'] = $this->_getGroupID($matches2['group']); + $this->_curPre['group_id'] = $this->_getGroupID($matches2['group']); } if ($matches['size'] !== 'N/A') { $this->_curPre['size'] = $matches['size']; @@ -281,28 +281,28 @@ class IRCScraper extends IRCClient $query = 'INSERT INTO prehash ('; - $query .= (!empty($this->_curPre['size']) ? 'size, ' : ''); - $query .= (!empty($this->_curPre['category']) ? 'category, ' : ''); - $query .= (!empty($this->_curPre['source']) ? 'source, ' : ''); - $query .= (!empty($this->_curPre['reason']) ? 'nukereason, ' : ''); - $query .= (!empty($this->_curPre['files']) ? 'files, ' : ''); - $query .= (!empty($this->_curPre['reqid']) ? 'requestid, ' : ''); - $query .= (!empty($this->_curPre['group_id']) ? 'groupid, ' : ''); - $query .= (!empty($this->_curPre['nuked']) ? 'nuked, ' : ''); - $query .= (!empty($this->_curPre['filename']) ? 'filename, ' : ''); + $query .= (!empty($this->_curPre['size']) ? 'size, ' : ''); + $query .= (!empty($this->_curPre['category']) ? 'category, ' : ''); + $query .= (!empty($this->_curPre['source']) ? 'source, ' : ''); + $query .= (!empty($this->_curPre['reason']) ? 'nukereason, ' : ''); + $query .= (!empty($this->_curPre['files']) ? 'files, ' : ''); + $query .= (!empty($this->_curPre['reqid']) ? 'requestid, ' : ''); + $query .= (!empty($this->_curPre['group_id']) ? 'groupid, ' : ''); + $query .= (!empty($this->_curPre['nuked']) ? 'nuked, ' : ''); + $query .= (!empty($this->_curPre['filename']) ? 'filename, ' : ''); $query .= 'predate, title) VALUES ('; - $query .= (!empty($this->_curPre['size']) ? $this->_pdo->escapeString($this->_curPre['size']) . ', ' : ''); - $query .= (!empty($this->_curPre['category']) ? $this->_pdo->escapeString($this->_curPre['category']) . ', ' : ''); - $query .= (!empty($this->_curPre['source']) ? $this->_pdo->escapeString($this->_curPre['source']) . ', ' : ''); - $query .= (!empty($this->_curPre['reason']) ? $this->_pdo->escapeString($this->_curPre['reason']) . ', ' : ''); - $query .= (!empty($this->_curPre['files']) ? $this->_pdo->escapeString($this->_curPre['files']) . ', ' : ''); - $query .= (!empty($this->_curPre['reqid']) ? $this->_curPre['reqid'] . ', ' : ''); - $query .= (!empty($this->_curPre['group_id']) ? $this->_curPre['group_id'] . ', ' : ''); - $query .= (!empty($this->_curPre['nuked']) ? $this->_curPre['nuked'] . ', ' : ''); - $query .= (!empty($this->_curPre['filename']) ? $this->_pdo->escapeString($this->_curPre['filename']) . ', ' : ''); - $query .= (!empty($this->_curPre['predate']) ? $this->_curPre['predate'] . ', ' : 'NOW(), '); + $query .= (!empty($this->_curPre['size']) ? $this->_pdo->escapeString($this->_curPre['size']) . ', ' : ''); + $query .= (!empty($this->_curPre['category']) ? $this->_pdo->escapeString($this->_curPre['category']) . ', ' : ''); + $query .= (!empty($this->_curPre['source']) ? $this->_pdo->escapeString($this->_curPre['source']) . ', ' : ''); + $query .= (!empty($this->_curPre['reason']) ? $this->_pdo->escapeString($this->_curPre['reason']) . ', ' : ''); + $query .= (!empty($this->_curPre['files']) ? $this->_pdo->escapeString($this->_curPre['files']) . ', ' : ''); + $query .= (!empty($this->_curPre['reqid']) ? $this->_curPre['reqid'] . ', ' : ''); + $query .= (!empty($this->_curPre['group_id']) ? $this->_curPre['group_id'] . ', ' : ''); + $query .= (!empty($this->_curPre['nuked']) ? $this->_curPre['nuked'] . ', ' : ''); + $query .= (!empty($this->_curPre['filename']) ? $this->_pdo->escapeString($this->_curPre['filename']) . ', ' : ''); + $query .= (!empty($this->_curPre['predate']) ? $this->_curPre['predate'] . ', ' : 'NOW(), '); $query .= '%s)'; @@ -331,26 +331,26 @@ class IRCScraper extends IRCClient $query = 'UPDATE prehash SET '; - $query .= (!empty($this->_curPre['size']) ? 'size = ' . $this->_pdo->escapeString($this->_curPre['size']) . ', ' : ''); - $query .= (!empty($this->_curPre['source']) ? 'source = ' . $this->_pdo->escapeString($this->_curPre['source']) . ', ' : ''); - $query .= (!empty($this->_curPre['files']) ? 'files = ' . $this->_pdo->escapeString($this->_curPre['files']) . ', ' : ''); - $query .= (!empty($this->_curPre['reason']) ? 'nukereason = ' . $this->_pdo->escapeString($this->_curPre['reason']) . ', ' : ''); - $query .= (!empty($this->_curPre['reqid']) ? 'requestid = ' . $this->_curPre['reqid'] . ', ' : ''); - $query .= (!empty($this->_curPre['group_id']) ? 'groupid = ' . $this->_curPre['group_id'] . ', ' : ''); - $query .= (!empty($this->_curPre['predate']) ? 'predate = ' . $this->_curPre['predate'] . ', ' : ''); - $query .= (!empty($this->_curPre['nuked']) ? 'nuked = ' . $this->_curPre['nuked'] . ', ' : ''); - $query .= (!empty($this->_curPre['filename']) ? 'filename = ' . $this->_pdo->escapeString($this->_curPre['filename']) . ', ' : ''); + $query .= (!empty($this->_curPre['size']) ? 'size = ' . $this->_pdo->escapeString($this->_curPre['size']) . ', ' : ''); + $query .= (!empty($this->_curPre['source']) ? 'source = ' . $this->_pdo->escapeString($this->_curPre['source']) . ', ' : ''); + $query .= (!empty($this->_curPre['files']) ? 'files = ' . $this->_pdo->escapeString($this->_curPre['files']) . ', ' : ''); + $query .= (!empty($this->_curPre['reason']) ? 'nukereason = ' . $this->_pdo->escapeString($this->_curPre['reason']) . ', ' : ''); + $query .= (!empty($this->_curPre['reqid']) ? 'requestid = ' . $this->_curPre['reqid'] . ', ' : ''); + $query .= (!empty($this->_curPre['group_id']) ? 'groupid = ' . $this->_curPre['group_id'] . ', ' : ''); + $query .= (!empty($this->_curPre['predate']) ? 'predate = ' . $this->_curPre['predate'] . ', ' : ''); + $query .= (!empty($this->_curPre['nuked']) ? 'nuked = ' . $this->_curPre['nuked'] . ', ' : ''); + $query .= (!empty($this->_curPre['filename']) ? 'filename = ' . $this->_pdo->escapeString($this->_curPre['filename']) . ', ' : ''); $query .= ( (empty($this->_oldPre['category']) && !empty($this->_curPre['category'])) ? 'category = ' . $this->_pdo->escapeString($this->_curPre['category']) . ', ' : '' ); - if ($query === 'UPDATE prehash SET '){ + if ($query === 'UPDATE prehash SET ') { return; } - $query .= 'title = ' . $this->_pdo->escapeString($this->_curPre['title']); + $query .= 'title = ' . $this->_pdo->escapeString($this->_curPre['title']); $query .= ' WHERE title = ' . $this->_pdo->escapeString($this->_curPre['title']); $this->_pdo->ping(true); @@ -373,7 +373,7 @@ class IRCScraper extends IRCClient $nukeString = ''; if ($this->_nuked !== false) { - switch((int)$this->_curPre['nuked']) { + switch ((int)$this->_curPre['nuked']) { case PreHash::PRE_NUKED: $nukeString = '[ NUKED ] '; break; diff --git a/lib/IRCScraper/scrape.php b/lib/IRCScraper/scrape.php index 33af0b2ad..e8f587a45 100644 --- a/lib/IRCScraper/scrape.php +++ b/lib/IRCScraper/scrape.php @@ -1,8 +1,8 @@ 11 && !preg_match( '/\A(\s*<\?xml|=newz\[NZB\]=|RIFF|\s*[RP]AR|.{0,10}(JFIF|matroska|ftyp|ID3))|;\s*Generated\s*by.*SF\w/i' - , $possibleNFO)) - { + , $possibleNFO)) { // File/GetId3 work with files, so save to disk. $tmpPath = $this->tmpPath . $guid . '.nfo'; file_put_contents($tmpPath, $possibleNFO); @@ -161,8 +162,7 @@ class Info // Or binary. } else if (preg_match('/^(JPE?G|Parity|PNG|RAR|XML|(7-)?[Zz]ip)/', $result) || - preg_match('/[\x00-\x08\x12-\x1F\x0B\x0E\x0F]/', $possibleNFO)) - { + preg_match('/[\x00-\x08\x12-\x1F\x0B\x0E\x0F]/', $possibleNFO)) { @unlink($tmpPath); return false; } @@ -251,7 +251,7 @@ class Info * @access public * @static */ - static public function NfoQueryString(DB &$pdo) + static public function NfoQueryString(DB & $pdo) { $s = new Sites(); $site = $s->get(); diff --git a/lib/Konsole.php b/lib/Konsole.php index 55ecb58d4..e27896bba 100644 --- a/lib/Konsole.php +++ b/lib/Konsole.php @@ -1,13 +1,13 @@ Items->Item->ItemAttributes->ESRBAgeRating; $con['releasedate'] = (string)$amaz->Items->Item->ItemAttributes->ReleaseDate; - if(!isset($con['releasedate'])){ + if (!isset($con['releasedate'])) { $con['releasedate'] = ""; } @@ -644,19 +644,19 @@ class Konsole $con['cover'] ) ); - if($con['cover'] === 1){ + if ($con['cover'] === 1) { $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250); } } else { $consoleId = $check['id']; - if($con['cover'] === 1){ + if ($con['cover'] === 1) { $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250); } $this->update( $consoleId, $con['title'], $con['asin'], $con['url'], $con['salesrank'], - $con['platform'], $con['publisher'], (isset($con['releasedate']) ? $con['releasedate']: null), $con['esrb'], + $con['platform'], $con['publisher'], (isset($con['releasedate']) ? $con['releasedate'] : null), $con['esrb'], $con['cover'], $con['consolegenreid'], (isset($con['review']) ? $con['review'] : null) ); } @@ -769,7 +769,7 @@ class Konsole $title = $matches['title']; // Replace dots, underscores, or brackets with spaces. - $result['title'] = str_replace(['.','_','%20', '[', ']'], ' ', $title); + $result['title'] = str_replace(['.', '_', '%20', '[', ']'], ' ', $title); $result['title'] = str_replace([' RF ', '.RF.', '-RF-', '_RF_'], ' ', $result['title']); //Remove format tags from release title for match $result['title'] = trim(preg_replace('/PAL|MULTI(\d)?|NTSC-?J?|\(JAPAN\)/i', '', $result['title'])); diff --git a/lib/MiscSorter.php b/lib/MiscSorter.php index c210b79d5..a827d50fb 100644 --- a/lib/MiscSorter.php +++ b/lib/MiscSorter.php @@ -221,6 +221,9 @@ class MiscSorter return $str; } + /** + * @param string $nfo + */ private function matchnfo($case, $nfo, $row) { $ok = false; @@ -659,6 +662,9 @@ class MiscSorter // tries to derive author and title of book from release NFO + /** + * @param string $nfo + */ private function _doAmazonMovies($amaz = array(), $id = 0, $nfo) { $new = (string)$amaz->Items->Item->ItemAttributes->Title; diff --git a/lib/NZBGet.php b/lib/NZBGet.php index 3b0616702..ae152a2ec 100644 --- a/lib/NZBGet.php +++ b/lib/NZBGet.php @@ -4,12 +4,12 @@ require_once(WWW_DIR . "/lib/releases.php"); require_once(WWW_DIR . "/lib/util.php"); require_once(WWW_DIR . "/lib/nzb.php"); /** - * Class NZBGet - * - * Transfers data between an NZBGet server and a newznab website. - * - * @package nzedb - */ + * Class NZBGet + * + * Transfers data between an NZBGet server and a newznab website. + * + * @package nzedb + */ class NZBGet { /** @@ -88,7 +88,7 @@ class NZBGet $this->rsstoken = $page->userdata['rsstoken']; if (!empty($page->userdata['nzbgeturl'])) { - $this->url = $page->userdata['nzbgeturl']; + $this->url = $page->userdata['nzbgeturl']; $this->userName = (empty($page->userdata['nzbgetusername']) ? '' : $page->userdata['nzbgetusername']); $this->password = (empty($page->userdata['nzbgetpassword']) ? '' : $page->userdata['nzbgetpassword']); } @@ -381,7 +381,7 @@ class NZBGet if ($xml) { $retVal = []; $i = 0; - foreach($xml->params->param->value->array->data->value as $value) { + foreach ($xml->params->param->value->array->data->value as $value) { foreach ($value->struct->member as $member) { $value = (array)$member->value; $value = array_shift($value); @@ -410,7 +410,7 @@ class NZBGet if ($data) { $xml = simplexml_load_string($data); if ($xml) { - foreach($xml->params->param->value->struct->member as $member) { + foreach ($xml->params->param->value->struct->member as $member) { $value = (array)$member->value; $value = array_shift($value); if (!is_object($value)) { @@ -432,7 +432,7 @@ class NZBGet * * @access public */ - public function verifyURL ($url) + public function verifyURL($url) { if (preg_match('/(?Phttps?):\/\/(?P.+?)(:(?P\d+\/)|\/)$/i', $url, $matches)) { return diff --git a/lib/Pprocess.php b/lib/Pprocess.php index d2a19855a..e2e22c589 100644 --- a/lib/Pprocess.php +++ b/lib/Pprocess.php @@ -17,7 +17,7 @@ require_once(WWW_DIR . "lib/amazon.php"); require_once(WWW_DIR . "lib/genres.php"); require_once(WWW_DIR . "lib/anidb.php"); require_once(WWW_DIR . "lib/book.php"); -require_once(WWW_DIR. "lib/Books.php"); +require_once(WWW_DIR . "lib/Books.php"); require_once(WWW_DIR . "lib/Games.php"); require_once(WWW_DIR . "lib/spotnab.php"); require_once(WWW_DIR . "lib/thetvdb.php"); @@ -124,7 +124,7 @@ class PProcess $this->_par2Info = new Par2Info(); $this->debugging = ($options['Logger'] instanceof Logger ? $options['Logger'] : new Logger(['ColorCLI' => $this->pdo->log])); $this->nameFixer = (($options['NameFixer'] instanceof NameFixer) ? $options['NameFixer'] : new NameFixer(['Echo' => $this->echooutput, 'Settings' => $this->pdo, 'Groups' => $this->groups])); - $this->Nfo = (($options['Nfo'] instanceof Info ) ? $options['Nfo'] : new Info(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); + $this->Nfo = (($options['Nfo'] instanceof Info) ? $options['Nfo'] : new Info(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); $this->releaseFiles = (($options['ReleaseFiles'] instanceof ReleaseFiles) ? $options['ReleaseFiles'] : new ReleaseFiles($this->pdo)); //\\ @@ -303,8 +303,7 @@ class PProcess public function processTvDB() { - if ($this->site->lookupthetvdb == 1) - { + if ($this->site->lookupthetvdb == 1) { $thetvdb = new TheTVDB($this->echooutput); $thetvdb->processReleases(); } diff --git a/lib/ProcessAdditional.php b/lib/ProcessAdditional.php index fa3845ec8..9f6380766 100644 --- a/lib/ProcessAdditional.php +++ b/lib/ProcessAdditional.php @@ -350,7 +350,7 @@ Class ProcessAdditional ); } - $this->_showCLIReleaseID = (PHP_BINARY . ' ' . __DIR__ . DS . 'ProcessAdditional.php ReleaseID: '); + $this->_showCLIReleaseID = (PHP_BINARY . ' ' . __DIR__ . DS . 'ProcessAdditional.php ReleaseID: '); // Maximum amount of releases to fetch per run. $this->_queryLimit = @@ -645,7 +645,7 @@ Class ProcessAdditional * Deletes files and folders recursively. * * @param string $path Path to a folder or file. - * @param array $ignoredFolders Array with paths to folders to ignore. + * @param string[] $ignoredFolders Array with paths to folders to ignore. * * @void * @access protected @@ -1678,7 +1678,7 @@ Class ProcessAdditional } else if ($ext === 'FLAC') { $newCat = Category::CAT_MUSIC_LOSSLESS; } else { - $newCat = $this->_categorize->determineCategory($rQuery['groupid'],$newName); + $newCat = $this->_categorize->determineCategory($rQuery['groupid'], $newName); } $newTitle = $this->pdo->escapeString(substr($newName, 0, 255)); @@ -1888,7 +1888,7 @@ Class ProcessAdditional $this->site->ffmpegpath . '" -i "' . $fileLocation . - '" -ss ' . ($time === '' ? '00:00:03.00' : $time) . + '" -ss ' . ($time === '' ? '00:00:03.00' : $time) . ' -vframes 1 -loglevel quiet -y "' . $fileName . '"' @@ -1949,12 +1949,14 @@ Class ProcessAdditional $newMethod = true; // Get the lowest time we can start making the video at based on how many seconds the admin wants the video to be. - if ($numbers[1] <= $this->_ffMPEGDuration) { // If the clip is shorter than the length we want. + if ($numbers[1] <= $this->_ffMPEGDuration) { +// If the clip is shorter than the length we want. // The lowest we want is 0. $lowestLength = '00:00:00.00'; - } else { // If the clip is longer than the length we want. + } else { +// If the clip is longer than the length we want. // The lowest we want is the the difference between the max video length and our wanted total time. $lowestLength = ($numbers[1] - $this->_ffMPEGDuration); @@ -2066,7 +2068,7 @@ Class ProcessAdditional if (is_file($fileLocation)) { // Run media info on it. - $xmlArray =runCmd( + $xmlArray = runCmd( $this->_killString . $this->site->mediainfopath . '" --Output=XML "' . $fileLocation . '"' ); @@ -2242,7 +2244,7 @@ Class ProcessAdditional /** * Try to get a title from a Linux_2rename.sh file for alt.binaries.u4e group. * - * @param $fileLocation + * @param string $fileLocation */ protected function _processU4ETitle($fileLocation) { @@ -2558,4 +2560,6 @@ Class ProcessAdditional } } -class ProcessAdditionalException extends Exception { } \ No newline at end of file +class ProcessAdditionalException extends Exception +{ +} \ No newline at end of file diff --git a/lib/ReleaseRemover.php b/lib/ReleaseRemover.php index ac6f789c2..791783b24 100644 --- a/lib/ReleaseRemover.php +++ b/lib/ReleaseRemover.php @@ -341,7 +341,7 @@ class ReleaseRemover /** * Remove releases with 15 or more letters or numbers, nothing else. * - * @return bool + * @return string|boolean */ protected function removeGibberish() { @@ -369,7 +369,7 @@ class ReleaseRemover /** * Remove releases with 25 or more letters/numbers, probably hashed. * - * @return bool + * @return string|boolean */ protected function removeHashed() { @@ -396,7 +396,7 @@ class ReleaseRemover /** * Remove releases with 5 or less letters/numbers. * - * @return bool + * @return string|boolean */ protected function removeShort() { @@ -423,7 +423,7 @@ class ReleaseRemover /** * Remove releases with an exe file not in other misc or pc apps/games. * - * @return bool + * @return string|boolean */ protected function removeExecutable() { @@ -456,7 +456,7 @@ class ReleaseRemover /** * Remove releases with an install.bin file. * - * @return bool + * @return string|boolean */ protected function removeInstallBin() { @@ -480,7 +480,7 @@ class ReleaseRemover /** * Remove releases with an password.url file. * - * @return bool + * @return string|boolean */ protected function removePasswordURL() { @@ -504,7 +504,7 @@ class ReleaseRemover /** * Remove releases with password in the search name. * - * @return bool + * @return string|boolean */ protected function removePassworded() { @@ -551,7 +551,7 @@ class ReleaseRemover /** * Remove releases smaller than 2MB with 1 part not in MP3/books/misc section. * - * @return bool + * @return string|boolean */ protected function removeSize() { @@ -586,7 +586,7 @@ class ReleaseRemover /** * Remove releases bigger than 200MB with just a single file. * - * @return bool + * @return string|boolean */ protected function removeHuge() { @@ -609,7 +609,7 @@ class ReleaseRemover /** * Remove releases with more than 1 part, less than 40MB, sample in name. TV/Movie sections. * - * @return bool + * @return string|boolean */ protected function removeSample() { @@ -650,7 +650,7 @@ class ReleaseRemover /** * Remove releases with a scr file in the filename/subject. * - * @return bool + * @return string|boolean */ protected function removeSCR() { @@ -755,7 +755,7 @@ class ReleaseRemover // Find first bd|dl instance position in Regex, then find last closing parenthesis as this is reversed. $forBegin = strpos($dbRegex, 'bd|dl'); $regexMatch = - str_replace(array('\\',']','['), '', + str_replace(array('\\', ']', '['), '', str_replace('bd|dl)mux', 'bdmux|dlmux', substr($dbRegex, $forBegin, strrpos($dbRegex, ')') - $forBegin @@ -943,7 +943,7 @@ class ReleaseRemover * Remove releases that contain .wmv files and Codec\Setup.exe files, aka that spam poster. * Thanks to dizant from nZEDb forums for parts of the sql query * - * @return bool + * @return string|boolean */ protected function removeCodecPoster() { @@ -1012,7 +1012,7 @@ class ReleaseRemover /** * Verify if the query has any results. * - * @return bool|int False on failure, count of found releases. + * @return boolean False on failure, count of found releases. */ protected function checkSelectQuery() { @@ -1037,7 +1037,7 @@ class ReleaseRemover * * @param string $argument User argument. * - * @return bool|string + * @return string|false */ protected function formatCriteriaQuery($argument) { @@ -1069,8 +1069,7 @@ class ReleaseRemover case 'equals': if ($args[2] === 'NULL') { return ' AND imdbid IS NULL '; - } - else { + } else { return ' AND imdbid = ' . $args[2]; } default: diff --git a/lib/Sharing.php b/lib/Sharing.php index d893acfb8..8d6c78668 100644 --- a/lib/Sharing.php +++ b/lib/Sharing.php @@ -76,7 +76,7 @@ Class Sharing */ public function __construct(array $options = []) { - $defaults= [ + $defaults = [ 'Settings' => null, 'NNTP' => null, ]; @@ -526,7 +526,7 @@ Class Sharing if (!isset($body['USER']) || !isset($body['SID']) || !isset($body['RID']) || !isset($body['TIME']) | !isset($body['BODY'])) { return false; } - $cid = md5($body['SID'].$body['USER'].$body['TIME'].$siteID); + $cid = md5($body['SID'] . $body['USER'] . $body['TIME'] . $siteID); // Insert the comment. if ($this->pdo->queryExec( diff --git a/lib/TraktTv.php b/lib/TraktTv.php index 1b687162c..c58f3fd04 100644 --- a/lib/TraktTv.php +++ b/lib/TraktTv.php @@ -71,7 +71,7 @@ Class TraktTv * * @access public */ - public function traktMoviesummary($movie = '', $array=false) + public function traktMoviesummary($movie = '', $array = false) { if (!empty($this->APIKEY)) { $MovieJson = Utility::getUrl([ @@ -79,7 +79,7 @@ Class TraktTv 'http://api.trakt.tv/movie/summary.json/' . $this->APIKEY . '/' . - str_replace([' ', '_', '.'], '-', str_replace(['(', ')'], '', $movie)) + str_replace([' ', '_', '.'], '-', str_replace(['(', ')'], '', $movie)) ] ); diff --git a/lib/TvAnger.php b/lib/TvAnger.php index a567223c3..25fdf6fc4 100644 --- a/lib/TvAnger.php +++ b/lib/TvAnger.php @@ -168,6 +168,9 @@ class TvAnger return $country; } + /** + * @param string $desc + */ public function add($rageID, $releasename, $desc, $genre, $country, $imgbytes) { $releasename = str_replace(array('.', '_'), array(' ', ' '), $releasename); @@ -514,6 +517,9 @@ class TvAnger return $result; } + /** + * @param string $rageID + */ public function getRageInfoFromService($rageID) { $result = array('genres' => '', 'country' => '', 'showid' => $rageID); diff --git a/lib/copy_this/www/admin/ajax_regex.php b/lib/copy_this/www/admin/ajax_regex.php index d483a2311..65f163d4d 100644 --- a/lib/copy_this/www/admin/ajax_regex.php +++ b/lib/copy_this/www/admin/ajax_regex.php @@ -11,15 +11,15 @@ if (!isset($_GET['action'])) { exit(); } -switch($_GET['action']) { +switch ($_GET['action']) { case 1: - $id = (int) $_GET['col_id']; + $id = (int)$_GET['col_id']; (new CollectionsCleaning(['Settings' => $admin->settings]))->deleteRegex($id); print "Regex $id deleted."; break; case 2: - $id = (int) $_GET['bin_id']; + $id = (int)$_GET['bin_id']; (new Binaries(['Settings' => $admin->settings]))->deleteBlacklist($id); print "Blacklist $id deleted."; break; diff --git a/lib/copy_this/www/admin/group-bulk.php b/lib/copy_this/www/admin/group-bulk.php index 2c94d978e..8fa574946 100644 --- a/lib/copy_this/www/admin/group-bulk.php +++ b/lib/copy_this/www/admin/group-bulk.php @@ -9,8 +9,7 @@ $page = new AdminPage(); // set the current action $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; -switch ($action) -{ +switch ($action) { case 'submit': if (isset($_POST['groupfilter']) && !empty($_POST['groupfilter'])) { $groups = new Groups; diff --git a/lib/copy_this/www/admin/release-edit.php b/lib/copy_this/www/admin/release-edit.php index f33d4fd13..755491964 100644 --- a/lib/copy_this/www/admin/release-edit.php +++ b/lib/copy_this/www/admin/release-edit.php @@ -13,14 +13,12 @@ $id = 0; // set the current action $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; -switch ($action) -{ +switch ($action) { case 'submit': $releases->update($_POST["id"], $_POST["name"], $_POST["searchname"], $_POST["fromname"], $_POST["category"], $_POST["totalpart"], $_POST["grabs"], $_POST["size"], $_POST["postdate"], $_POST["adddate"], $_POST["rageid"], $_POST["seriesfull"], $_POST["season"], $_POST["episode"], $_POST['imdbid'], $_POST['anidbid'], $_POST['tvdbid'], $_POST['consoleinfoid']); - if (isset($_POST['from']) && !empty($_POST['from'])) - { + if (isset($_POST['from']) && !empty($_POST['from'])) { header("Location:" . $_POST['from']); exit; } @@ -30,23 +28,20 @@ switch ($action) case 'view': default: - if (isset($_GET["id"])) - { + if (isset($_GET["id"])) { $page->title = "Release Edit"; $id = $_GET["id"]; $release = $releases->getByID($id); - if ($release && $release["imdbid"] != "") - { + if ($release && $release["imdbid"] != "") { require_once(WWW_DIR . "/lib/movie.php"); $movie = new Movie(); $mov = $movie->getMovieInfo($release['imdbid']); $page->smarty->assign('updatename', $mov["title"]); } - if ($release && $release["musicinfoid"] != "") - { + if ($release && $release["musicinfoid"] != "") { require_once(WWW_DIR . "/lib/music.php"); $music = new Music(); $mus = $music->getMusicInfo($release['musicinfoid']); diff --git a/lib/copy_this/www/admin/site-edit.php b/lib/copy_this/www/admin/site-edit.php index 68934bc1a..bfd79208c 100644 --- a/lib/copy_this/www/admin/site-edit.php +++ b/lib/copy_this/www/admin/site-edit.php @@ -12,8 +12,7 @@ $id = 0; // set the current action $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; -switch ($action) -{ +switch ($action) { case 'submit': if (!empty($_POST['book_reqids'])) { @@ -23,34 +22,31 @@ switch ($action) } $error = ""; $ret = $sites->update($_POST); - if (is_int($ret)) - { - if ($ret == Sites::ERR_BADUNRARPATH) - $error = "The unrar path does not point to a valid binary"; - elseif ($ret == Sites::ERR_BADFFMPEGPATH) - $error = "The ffmpeg path does not point to a valid binary"; - elseif ($ret == Sites::ERR_BADMEDIAINFOPATH) - $error = "The mediainfo path does not point to a valid binary"; - elseif ($ret == Sites::ERR_BADNZBPATH) - $error = "The nzb path does not point to a valid directory"; - elseif ($ret == Sites::ERR_DEEPNOUNRAR) - $error = "Deep password check requires a valid path to unrar binary"; - elseif ($ret == Sites::ERR_BADTMPUNRARPATH) - $error = "The temp unrar path is not a valid directory"; - elseif ($ret == Sites::ERR_BADLAMEPATH) - $error = "The lame path is not a valid directory"; - elseif ($ret == Sites::ERR_SABCOMPLETEPATH) - $error = "The sab complete path is not a valid directory"; + if (is_int($ret)) { + if ($ret == Sites::ERR_BADUNRARPATH) { + $error = "The unrar path does not point to a valid binary"; + } elseif ($ret == Sites::ERR_BADFFMPEGPATH) { + $error = "The ffmpeg path does not point to a valid binary"; + } elseif ($ret == Sites::ERR_BADMEDIAINFOPATH) { + $error = "The mediainfo path does not point to a valid binary"; + } elseif ($ret == Sites::ERR_BADNZBPATH) { + $error = "The nzb path does not point to a valid directory"; + } elseif ($ret == Sites::ERR_DEEPNOUNRAR) { + $error = "Deep password check requires a valid path to unrar binary"; + } elseif ($ret == Sites::ERR_BADTMPUNRARPATH) { + $error = "The temp unrar path is not a valid directory"; + } elseif ($ret == Sites::ERR_BADLAMEPATH) { + $error = "The lame path is not a valid directory"; + } elseif ($ret == Sites::ERR_SABCOMPLETEPATH) { + $error = "The sab complete path is not a valid directory"; + } } - if ($error == "") - { + if ($error == "") { $site = $ret; $returnid = $site->id; header("Location:" . WWW_TOP . "/site-edit.php?id=" . $returnid); - } - else - { + } else { $page->smarty->assign('error', $error); $site = $sites->row2Object($_POST); $page->smarty->assign('fsite', $site); @@ -146,14 +142,16 @@ $page->smarty->assign('book_reqids_selected', $books_selected); $themelist = array(); $themes = scandir(WWW_DIR . "/templates"); -foreach ($themes as $theme) +foreach ($themes as $theme) { if (strpos($theme, ".") === false && is_dir(WWW_DIR . "/templates/" . $theme)) $themelist[] = $theme; +} $page->smarty->assign('themelist', $themelist); -if (strpos(NNTP_SERVER, "astra") === false) +if (strpos(NNTP_SERVER, "astra") === false) { $page->smarty->assign('compress_headers_warning', "compress_headers_warning"); +} $page->content = $page->smarty->fetch('site-edit.tpl'); $page->render(); \ No newline at end of file diff --git a/lib/copy_this/www/admin/tmux-edit.php b/lib/copy_this/www/admin/tmux-edit.php index c10c96711..8fdc67773 100644 --- a/lib/copy_this/www/admin/tmux-edit.php +++ b/lib/copy_this/www/admin/tmux-edit.php @@ -10,8 +10,7 @@ $id = 0; // Set the current action. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; -switch ($action) -{ +switch ($action) { case 'submit': $error = ""; $ret = $tmux->update($_POST); diff --git a/lib/copy_this/www/admin/user-edit.php b/lib/copy_this/www/admin/user-edit.php index db8075dc6..5088f96e5 100644 --- a/lib/copy_this/www/admin/user-edit.php +++ b/lib/copy_this/www/admin/user-edit.php @@ -43,38 +43,40 @@ switch ($action) { if ($_POST["id"] == "") { $invites = $defaultinvites; foreach ($userroles as $role) { - if ($role['id'] == $_POST['role']) - $invites = $role['defaultinvites']; + if ($role['id'] == $_POST['role']) { + $invites = $role['defaultinvites']; + } } $ret = $users->signup($_POST["username"], $_POST["password"], $_POST["email"], '', $_POST["role"], $_POST["notes"], $invites, "", true, false, false, true); } else { $ret = $users->update($_POST["id"], $_POST["username"], $_POST["email"], $_POST["grabs"], $_POST["role"], $_POST["notes"], $_POST["invites"], (isset($_POST['movieview']) ? "1" : "0"), (isset($_POST['musicview']) ? "1" : "0"), (isset($_POST['gameview']) ? "1" : "0"), (isset($_POST['xxxview']) ? "1" : "0"), (isset($_POST['consoleview']) ? "1" : "0"), (isset($_POST['bookview']) ? "1" : "0")); - if ($_POST['password'] != "") - $users->updatePassword($_POST["id"], $_POST['password']); + if ($_POST['password'] != "") { + $users->updatePassword($_POST["id"], $_POST['password']); + } } - if ($ret >= 0) - header("Location:" . WWW_TOP . "/user-list.php"); - else { + if ($ret >= 0) { + header("Location:" . WWW_TOP . "/user-list.php"); + } else { switch ($ret) { - case Users::ERR_SIGNUP_BADUNAME: - $page->smarty->assign('error', "Bad username. Try a better one."); - break; - case Users::ERR_SIGNUP_BADPASS: - $page->smarty->assign('error', "Bad password. Try a longer one."); - break; - case Users::ERR_SIGNUP_BADEMAIL: - $page->smarty->assign('error', "Bad email."); - break; - case Users::ERR_SIGNUP_UNAMEINUSE: - $page->smarty->assign('error', "Username in use."); - break; - case Users::ERR_SIGNUP_EMAILINUSE: - $page->smarty->assign('error', "Email in use."); - break; - default: - $page->smarty->assign('error', "Unknown save error."); - break; + case Users::ERR_SIGNUP_BADUNAME: + $page->smarty->assign('error', "Bad username. Try a better one."); + break; + case Users::ERR_SIGNUP_BADPASS: + $page->smarty->assign('error', "Bad password. Try a longer one."); + break; + case Users::ERR_SIGNUP_BADEMAIL: + $page->smarty->assign('error', "Bad email."); + break; + case Users::ERR_SIGNUP_UNAMEINUSE: + $page->smarty->assign('error', "Username in use."); + break; + case Users::ERR_SIGNUP_EMAILINUSE: + $page->smarty->assign('error', "Email in use."); + break; + default: + $page->smarty->assign('error', "Unknown save error."); + break; } $user = array(); $user["id"] = $_POST["id"]; diff --git a/lib/copy_this/www/lib/Greenlight.php b/lib/copy_this/www/lib/Greenlight.php index 1e370288c..632773503 100644 --- a/lib/copy_this/www/lib/Greenlight.php +++ b/lib/copy_this/www/lib/Greenlight.php @@ -281,7 +281,7 @@ class Greenlight { $title = preg_replace('/[^\w]/', '', $title); $searchtitle = preg_replace('/[^\w]/', '', $searchtitle); - similar_text($title , $searchtitle, $p); + similar_text($title, $searchtitle, $p); if ($p == 100) { return true; } else { diff --git a/lib/copy_this/www/lib/Musik.php b/lib/copy_this/www/lib/Musik.php index 4b30ee2ec..cc4b999d0 100644 --- a/lib/copy_this/www/lib/Musik.php +++ b/lib/copy_this/www/lib/Musik.php @@ -558,7 +558,7 @@ class Musik } /** - * @param $title + * @param string $title * * @return boolean */ diff --git a/lib/copy_this/www/lib/ReleaseCleaning.php b/lib/copy_this/www/lib/ReleaseCleaning.php index 38a9b1901..1085425f1 100644 --- a/lib/copy_this/www/lib/ReleaseCleaning.php +++ b/lib/copy_this/www/lib/ReleaseCleaning.php @@ -367,6 +367,10 @@ class ReleaseCleaning "cleansubject" => $this->releaseCleanerHelper($this->subject), "properlynamed" => false ); } + + /** + * @param string $subject + */ public function releaseCleanerHelper($subject) { $cleanerName = preg_replace('/(- )?yEnc$/', '', $subject); @@ -375,6 +379,10 @@ class ReleaseCleaning // // Cleans release name for the namefixer class. // + + /** + * @param string $name + */ public function fixerCleaner($name) { //Extensions. diff --git a/lib/copy_this/www/lib/RequestID.php b/lib/copy_this/www/lib/RequestID.php index 2ae04a8c0..aae6e9cc6 100644 --- a/lib/copy_this/www/lib/RequestID.php +++ b/lib/copy_this/www/lib/RequestID.php @@ -12,8 +12,8 @@ abstract class RequestID const REQID_NONE = -3; // The Request id was not found locally or via web lookup. const REQID_ZERO = -2; // The Request id was 0. const REQID_NOLL = -1; // Request id was not found via local lookup. - const REQID_UPROC = 0; // Release has not been processed. - const REQID_FOUND = 1; // Request id found and release was updated. + const REQID_UPROC = 0; // Release has not been processed. + const REQID_FOUND = 1; // Request id found and release was updated. /** * @var Groups @@ -91,14 +91,18 @@ abstract class RequestID /** * Fetch releases with requestid's from MySQL. */ - protected function _getReleases() { } + protected function _getReleases() + { +} /** * Process releases for requestid's. * * @return int How many did we rename? */ - protected function _processReleases() { } + protected function _processReleases() + { +} /** * No request id was found, update the release. @@ -125,7 +129,9 @@ abstract class RequestID * * @return array|bool */ - protected function _getNewTitle() { } + protected function _getNewTitle() + { +} /** * Find a RequestID in a usenet subject. @@ -140,9 +146,9 @@ abstract class RequestID case preg_match('/\[\s*(\d+)\s*\]/', $this->_release['name'], $requestID): case preg_match('/^REQ\s*(\d{4,6})/i', $this->_release['name'], $requestID): case preg_match('/^(\d{4,6})-\d{1}\[/', $this->_release['name'], $requestID): - case preg_match('/(\d{4,6}) -/',$this->_release['name'], $requestID): - if ((int) $requestID[1] > 0) { - return (int) $requestID[1]; + case preg_match('/(\d{4,6}) -/', $this->_release['name'], $requestID): + if ((int)$requestID[1] > 0) { + return (int)$requestID[1]; } } return self::REQID_ZERO; diff --git a/lib/copy_this/www/lib/RequestIDWeb.php b/lib/copy_this/www/lib/RequestIDWeb.php index 356440e67..451d16542 100644 --- a/lib/copy_this/www/lib/RequestIDWeb.php +++ b/lib/copy_this/www/lib/RequestIDWeb.php @@ -43,7 +43,7 @@ class RequestIDWeb extends RequestID protected function _getReleases() { $this->_releases = $this->pdo->queryDirect( - sprintf (' + sprintf(' SELECT r.id, r.name, r.searchname, g.name AS groupname, r.groupid, r.categoryid FROM releases r INNER JOIN groups g ON r.groupid = g.id @@ -113,7 +113,7 @@ class RequestIDWeb extends RequestID if ($this->_releases instanceof \Traversable) { // Loop all the results. - foreach($this->_releases as $release) { + foreach ($this->_releases as $release) { $this->_release['name'] = $release['name']; // Try to find a request id for the release. @@ -170,7 +170,7 @@ class RequestIDWeb extends RequestID $returnedIdentifiers = []; $groupIDArray = []; - foreach($returnXml->request as $result) { + foreach ($returnXml->request as $result) { if (isset($result['name']) && isset($result['ident']) && (int)$result['ident'] > 0) { $this->_newTitle['title'] = (string)$result['name']; $this->_requestID = (int)$result['reqid']; @@ -221,7 +221,7 @@ class RequestIDWeb extends RequestID $status = self::REQID_NONE; if ($addDate !== false && !empty($addDate['adddate'])) { - if ((bool) (intval((time() - (int)$addDate['adddate']) / 3600) > $this->_request_hours)) { + if ((bool)(intval((time() - (int)$addDate['adddate']) / 3600) > $this->_request_hours)) { $status = self::REQID_OLD; } } else { diff --git a/lib/copy_this/www/lib/SmartyUtils.php b/lib/copy_this/www/lib/SmartyUtils.php index 16730520b..08077c4f9 100644 --- a/lib/copy_this/www/lib/SmartyUtils.php +++ b/lib/copy_this/www/lib/SmartyUtils.php @@ -1,26 +1,26 @@ . - * @author niel - * @copyright 2014 nZEDb - */ + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see LICENSE.txt in the base directory. If + * not, see: + * + * @link . + * @author niel + * @copyright 2014 nZEDb + */ // Function inspired by c0r3@newznabforums adds country flags on the browse page. -function release_flag ($x, $t) +function release_flag($x, $t) { $y = $d = ""; diff --git a/lib/copy_this/www/lib/SphinxSearch.php b/lib/copy_this/www/lib/SphinxSearch.php index 8a89bd5b1..28f4d2e71 100644 --- a/lib/copy_this/www/lib/SphinxSearch.php +++ b/lib/copy_this/www/lib/SphinxSearch.php @@ -80,8 +80,8 @@ class SphinxSearch public static function escapeString($string) { - $from = array ('\\', '(',')','|','---','--','-','!','@','~','"','&', '/', '^', '$', '=', "'", "\x00", "\n", "\r", "\x1a"); - $to = array ('\\\\\\\\','\\\\\\\\(','\\\\\\\\)','\\\\\\\\|','-','-','\\\\\\\\-','\\\\\\\\!','\\\\\\\\@','\\\\\\\\~', + $from = array('\\', '(', ')', '|', '---', '--', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=', "'", "\x00", "\n", "\r", "\x1a"); + $to = array('\\\\\\\\', '\\\\\\\\(', '\\\\\\\\)', '\\\\\\\\|', '-', '-', '\\\\\\\\-', '\\\\\\\\!', '\\\\\\\\@', '\\\\\\\\~', '\\\\\\\\"', '\\\\\\\\&', '\\\\\\\\/', '\\\\\\\\^', '\\\\\\\\$', '\\\\\\\\=', "\\'", "\\x00", "\\n", "\\r", "\\x1a"); return str_replace($from, $to, $string); } diff --git a/lib/copy_this/www/lib/Steam.php b/lib/copy_this/www/lib/Steam.php index 32d541c80..a5b25abae 100644 --- a/lib/copy_this/www/lib/Steam.php +++ b/lib/copy_this/www/lib/Steam.php @@ -136,7 +136,7 @@ class Steam $totaldetails = count($textarr) - 1; for ($i = 0; $i <= $totaldetails;) { if ($textarr[$i] == "Release Date") { - $pregmatchdate = $textarr[$i+1]; + $pregmatchdate = $textarr[$i + 1]; if (preg_match_all('#(?P[0-3]?\d)[^\d]|(?PJan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)|(?P(19|20)\d{2})#i', $pregmatchdate, $matches)) { @@ -151,8 +151,8 @@ class Steam } } } - $this->_res['gamedetails'][$textarr[$i]] = $textarr[$i+1]; - $i = $i+2; + $this->_res['gamedetails'][$textarr[$i]] = $textarr[$i + 1]; + $i = $i + 2; } } @@ -217,9 +217,9 @@ class Steam } if ($this->_ret = $this->_html->find("div.screenshot_holder", 0)) { if ($this->_ret = $this->_ret->find("a", 0)) { - if(preg_match('/\?url\=(?.*)/', $this->_ret->href, $matches)){ + if (preg_match('/\?url\=(?.*)/', $this->_ret->href, $matches)) { $this->_res['backdrop'] = trim($matches['imgurl']); - }else{ + } else { $this->_res['backdrop'] = trim($this->_ret->href); } @@ -330,7 +330,7 @@ class Steam { if (isset($this->cookie)) { $this->extractCookies(file_get_contents($this->cookie)); - if($this->_ageCheckSet === false) { + if ($this->_ageCheckSet === false) { $this->_postParams = array( "snr" => "1_agecheck_agecheck__age-gate", "ageDay" => "1", @@ -388,7 +388,7 @@ class Steam * * @param string $string The contents of the cookie file. * - * @return bool True/False if lastagecheckage and birthtime exists. + * @return boolean|null True/False if lastagecheckage and birthtime exists. */ private function extractCookies($string) { diff --git a/lib/copy_this/www/lib/TMDb.php b/lib/copy_this/www/lib/TMDb.php index 412cb3ca0..2c366b957 100644 --- a/lib/copy_this/www/lib/TMDb.php +++ b/lib/copy_this/www/lib/TMDb.php @@ -1,16 +1,16 @@ _apikey = (string) $apikey; + $this->_apikey = (string)$apikey; $this->_apischeme = ($scheme == TMDb::API_SCHEME) ? TMDb::API_SCHEME : TMDb::API_SCHEME_SSL; $this->setLang($default_lang); - if($config === TRUE) + if ($config === TRUE) { $this->getConfiguration(); } @@ -97,9 +97,9 @@ class TMDb { $params = array( 'query' => $query, - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), - 'include_adult' => (bool) $adult, + 'include_adult' => (bool)$adult, 'year' => $year, ); return $this->_makeCall('search/movie', $params); @@ -117,8 +117,8 @@ class TMDb { $params = array( 'query' => $query, - 'page' => (int) $page, - 'include_adult' => (bool) $adult, + 'page' => (int)$page, + 'include_adult' => (bool)$adult, ); return $this->_makeCall('search/person', $params); } @@ -151,7 +151,7 @@ class TMDb $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('collection/'.$id, $params); + return $this->_makeCall('collection/' . $id, $params); } /** @@ -165,9 +165,9 @@ class TMDb { $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), - 'append_to_response' => 'releases,trailers', + 'append_to_response' => 'releases,trailers', ); - return $this->_makeCall('movie/'.$id, $params); + return $this->_makeCall('movie/' . $id, $params); } /** @@ -182,7 +182,7 @@ class TMDb $params = array( 'country' => $country, ); - return $this->_makeCall('movie/'.$id.'/alternative_titles', $params); + return $this->_makeCall('movie/' . $id . '/alternative_titles', $params); } /** @@ -193,7 +193,7 @@ class TMDb */ public function getMovieCast($id) { - return $this->_makeCall('movie/'.$id.'/casts'); + return $this->_makeCall('movie/' . $id . '/casts'); } /** @@ -204,7 +204,7 @@ class TMDb */ public function getMovieKeywords($id) { - return $this->_makeCall('movie/'.$id.'/keywords'); + return $this->_makeCall('movie/' . $id . '/keywords'); } /** @@ -215,7 +215,7 @@ class TMDb */ public function getMovieReleases($id) { - return $this->_makeCall('movie/'.$id.'/releases'); + return $this->_makeCall('movie/' . $id . '/releases'); } /** @@ -226,7 +226,7 @@ class TMDb */ public function getMovieTranslations($id) { - return $this->_makeCall('movie/'.$id.'/translations'); + return $this->_makeCall('movie/' . $id . '/translations'); } /** @@ -241,7 +241,7 @@ class TMDb $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('movie/'.$id.'/trailers', $params); + return $this->_makeCall('movie/' . $id . '/trailers', $params); } /** @@ -256,7 +256,7 @@ class TMDb $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('movie/'.$id.'/images', $params); + return $this->_makeCall('movie/' . $id . '/images', $params); } /** @@ -270,10 +270,10 @@ class TMDb public function getSimilarMovies($id, $page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('movie/'.$id.'/similar_movies', $params); + return $this->_makeCall('movie/' . $id . '/similar_movies', $params); } /** @@ -296,7 +296,7 @@ class TMDb public function getUpcomingMovies($page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); return $this->_makeCall('movie/upcoming', $params); @@ -312,7 +312,7 @@ class TMDb public function getNowPlayingMovies($page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); return $this->_makeCall('movie/now_playing', $params); @@ -328,7 +328,7 @@ class TMDb public function getPopularMovies($page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); return $this->_makeCall('movie/popular', $params); @@ -344,7 +344,7 @@ class TMDb public function getTopRatedMovies($page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); return $this->_makeCall('movie/top_rated', $params); @@ -358,7 +358,7 @@ class TMDb */ public function getMovieChanges($id) { - return $this->_makeCall('movie/'.$id.'/changes'); + return $this->_makeCall('movie/' . $id . '/changes'); } /** @@ -372,7 +372,7 @@ class TMDb public function getChangedMovies($page = 1, $start_date = NULL, $end_date = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'start_date' => $start_date, 'end_date' => $end_date, ); @@ -387,7 +387,7 @@ class TMDb */ public function getPerson($id) { - return $this->_makeCall('person/'.$id); + return $this->_makeCall('person/' . $id); } /** @@ -402,7 +402,7 @@ class TMDb $params = array( 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('person/'.$id.'/credits', $params); + return $this->_makeCall('person/' . $id . '/credits', $params); } /** @@ -413,7 +413,7 @@ class TMDb */ public function getPersonImages($id) { - return $this->_makeCall('person/'.$id.'/images'); + return $this->_makeCall('person/' . $id . '/images'); } /** @@ -424,7 +424,7 @@ class TMDb */ public function getPersonChanges($id) { - return $this->_makeCall('person/'.$id.'/changes'); + return $this->_makeCall('person/' . $id . '/changes'); } /** @@ -438,7 +438,7 @@ class TMDb public function getChangedPersons($page = 1, $start_date = NULL, $end_date = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'start_date' => $start_date, 'start_date' => $end_date, ); @@ -453,7 +453,7 @@ class TMDb */ public function getCompany($id) { - return $this->_makeCall('company/'.$id); + return $this->_makeCall('company/' . $id); } /** @@ -467,10 +467,10 @@ class TMDb public function getMoviesByCompany($id, $page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('company/'.$id.'/movies', $params); + return $this->_makeCall('company/' . $id . '/movies', $params); } /** @@ -498,10 +498,10 @@ class TMDb public function getMoviesByGenre($id, $page = 1, $lang = NULL) { $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : $this->getLang(), ); - return $this->_makeCall('genre/'.$id.'/movies', $params); + return $this->_makeCall('genre/' . $id . '/movies', $params); } /** @@ -514,9 +514,9 @@ class TMDb { $result = $this->_makeCall('authentication/token/new'); - if( ! isset($result['request_token'])) + if (!isset($result['request_token'])) { - if($this->getDebugMode()) + if ($this->getDebugMode()) { throw new TMDbException('No valid request token from TMDb'); } @@ -544,7 +544,7 @@ class TMDb $result = $this->_makeCall('authentication/session/new', $params); - if(isset($result['session_id'])) + if (isset($result['session_id'])) { $this->setAuthSession($result['session_id']); } @@ -588,10 +588,10 @@ class TMDb { $session_id = ($session_id === NULL) ? $this->_session_id : $session_id; $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : '', ); - return $this->_makeCall('account/'.$account_id.'/favorite_movies', $params, $session_id); + return $this->_makeCall('account/' . $account_id . '/favorite_movies', $params, $session_id); } /** @@ -607,10 +607,10 @@ class TMDb { $session_id = ($session_id === NULL) ? $this->_session_id : $session_id; $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : '', ); - return $this->_makeCall('account/'.$account_id.'/rated_movies', $params, $session_id); + return $this->_makeCall('account/' . $account_id . '/rated_movies', $params, $session_id); } /** @@ -626,10 +626,10 @@ class TMDb { $session_id = ($session_id === NULL) ? $this->_session_id : $session_id; $params = array( - 'page' => (int) $page, + 'page' => (int)$page, 'language' => ($lang !== NULL) ? $lang : '', ); - return $this->_makeCall('account/'.$account_id.'/movie_watchlist', $params, $session_id); + return $this->_makeCall('account/' . $account_id . '/movie_watchlist', $params, $session_id); } /** @@ -645,10 +645,10 @@ class TMDb { $session_id = ($session_id === NULL) ? $this->_session_id : $session_id; $params = array( - 'movie_id' => (int) $movie_id, - 'favorite' => (bool) $favorite, + 'movie_id' => (int)$movie_id, + 'favorite' => (bool)$favorite, ); - return $this->_makeCall('account/'.$account_id.'/favorite', $params, $session_id, TMDb::POST); + return $this->_makeCall('account/' . $account_id . '/favorite', $params, $session_id, TMDb::POST); } /** @@ -664,10 +664,10 @@ class TMDb { $session_id = ($session_id === NULL) ? $this->_session_id : $session_id; $params = array( - 'movie_id' => (int) $movie_id, - 'movie_watchlist' => (bool) $watchlist, + 'movie_id' => (int)$movie_id, + 'movie_watchlist' => (bool)$watchlist, ); - return $this->_makeCall('account/'.$account_id.'/movie_watchlist', $params, $session_id, TMDb::POST); + return $this->_makeCall('account/' . $account_id . '/movie_watchlist', $params, $session_id, TMDb::POST); } /** @@ -684,7 +684,7 @@ class TMDb $params = array( 'value' => is_numeric($value) ? floatval($value) : 0, ); - return $this->_makeCall('movie/'.$movie_id.'/rating', $params, $session_id, TMDb::POST); + return $this->_makeCall('movie/' . $movie_id . '/rating', $params, $session_id, TMDb::POST); } /** @@ -696,7 +696,7 @@ class TMDb { $config = $this->_makeCall('configuration'); - if( ! empty($config)) + if (!empty($config)) { $this->setConfig($config); } @@ -716,18 +716,18 @@ class TMDb { $config = $this->getConfig(); - if(isset($config['images'])) + if (isset($config['images'])) { $base_url = $config['images']['base_url']; $available_sizes = $this->getAvailableImageSizes($imagetype); - if(in_array($size, $available_sizes)) + if (in_array($size, $available_sizes)) { - return $base_url.$size.$filepath; + return $base_url . $size . $filepath; } else { - throw new TMDbException('The size "'.$size.'" is not supported by TMDb'); + throw new TMDbException('The size "' . $size . '" is not supported by TMDb'); } } else @@ -746,9 +746,9 @@ class TMDb { $config = $this->getConfig(); - if(isset($config['images'][$imagetype.'_sizes'])) + if (isset($config['images'][$imagetype . '_sizes'])) { - return $config['images'][$imagetype.'_sizes']; + return $config['images'][$imagetype . '_sizes']; } else { @@ -779,24 +779,24 @@ class TMDb */ private function _makeCall($function, $params = NULL, $session_id = NULL, $method = TMDb::GET) { - $params = ( ! is_array($params)) ? array() : $params; + $params = (!is_array($params)) ? array() : $params; $auth_array = array('api_key' => $this->_apikey); - if($session_id !== NULL) + if ($session_id !== NULL) { $auth_array['session_id'] = $session_id; } - $url = $this->_apischeme.TMDb::API_URL.'/'.TMDb::API_VERSION.'/'.$function.'?'.http_build_query($auth_array, '', '&'); + $url = $this->_apischeme . TMDb::API_URL . '/' . TMDb::API_VERSION . '/' . $function . '?' . http_build_query($auth_array, '', '&'); - if($method === TMDb::GET) + if ($method === TMDb::GET) { - if(isset($params['language']) AND $params['language'] === FALSE) + if (isset($params['language']) AND $params['language'] === FALSE) { unset($params['language']); } - $url .= ( ! empty($params)) ? '&'.http_build_query($params, '', '&') : ''; + $url .= (!empty($params)) ? '&' . http_build_query($params, '', '&') : ''; } $results = '{}'; @@ -809,15 +809,15 @@ class TMDb $ch = curl_init(); - if($method == TMDB::POST) + if ($method == TMDB::POST) { $json_string = json_encode($params); - curl_setopt($ch,CURLOPT_POST, 1); - curl_setopt($ch,CURLOPT_POSTFIELDS, $json_string); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string); $headers[] = 'Content-Type: application/json'; - $headers[] = 'Content-Length: '.strlen($json_string); + $headers[] = 'Content-Length: ' . strlen($json_string); } - elseif($method == TMDb::HEAD) + elseif ($method == TMDb::HEAD) { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); curl_setopt($ch, CURLOPT_NOBODY, 1); @@ -837,9 +837,9 @@ class TMDb $error_number = curl_errno($ch); $error_message = curl_error($ch); - if($error_number > 0) + if ($error_number > 0) { - throw new TMDbException('Method failed: '.$function.' - '.$error_message); + throw new TMDbException('Method failed: ' . $function . ' - ' . $error_message); } curl_close($ch); @@ -851,17 +851,17 @@ class TMDb $results = json_decode($body, TRUE); - if(strpos($function, 'authentication/token/new') !== FALSE) + if (strpos($function, 'authentication/token/new') !== FALSE) { $parsed_headers = $this->_http_parse_headers($header); $results['Authentication-Callback'] = $parsed_headers['Authentication-Callback']; } - if($results !== NULL) + if ($results !== NULL) { return $results; } - elseif($method == TMDb::HEAD) + elseif ($method == TMDb::HEAD) { return $this->_http_parse_headers($header); } @@ -910,7 +910,7 @@ class TMDb */ public function getConfig() { - if(empty($this->_config)) + if (empty($this->_config)) { $this->_config = $this->getConfiguration(); } @@ -928,12 +928,12 @@ class TMDb { $return = array(); $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); - foreach($fields as $field) + foreach ($fields as $field) { - if(preg_match('/([^:]+): (.+)/m', $field, $match)) + if (preg_match('/([^:]+): (.+)/m', $field, $match)) { $match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1]))); - if( isset($return[$match[1]]) ) + if (isset($return[$match[1]])) { $return[$match[1]] = array($return[$match[1]], $match[2]); } @@ -952,4 +952,4 @@ class TMDb * * @author Jonas De Smet - Glamorous */ -class TMDbException extends Exception{} \ No newline at end of file +class TMDbException extends Exception {} \ No newline at end of file diff --git a/lib/copy_this/www/lib/Tmux.php b/lib/copy_this/www/lib/Tmux.php index 3b28f40cf..294a50aa3 100644 --- a/lib/copy_this/www/lib/Tmux.php +++ b/lib/copy_this/www/lib/Tmux.php @@ -298,6 +298,9 @@ class Tmux return ((float)$usec + (float)$sec); } + /** + * @param double $bytes + */ public function decodeSize($bytes) { $types = ['B', 'KB', 'MB', 'GB', 'TB']; @@ -379,7 +382,7 @@ class Tmux public function proc_query($qry, $bookreqids, $request_hours, $db_name) { - switch ((int) $qry) { + switch ((int)$qry) { case 1: return sprintf("SELECT (SELECT COUNT(*) FROM releases WHERE nzbstatus = 1 AND categoryid BETWEEN 5000 AND 5999 AND rageid = -1) AS processtvrage, diff --git a/lib/copy_this/www/lib/TmuxOutput.php b/lib/copy_this/www/lib/TmuxOutput.php index 48ad94656..8623a2fa3 100644 --- a/lib/copy_this/www/lib/TmuxOutput.php +++ b/lib/copy_this/www/lib/TmuxOutput.php @@ -120,7 +120,7 @@ class TmuxOutput extends Tmux $tversion = '0.6r0138'; $buffer .= sprintf($this->tmpMasks[2], - "Monitor $state v$tversion @ $this->_tvers [" . $this->_vers ."]: ", + "Monitor $state v$tversion @ $this->_tvers [" . $this->_vers . "]: ", $this->relativeTime($this->runVar['timers']['timer1']) ); @@ -518,9 +518,9 @@ class TmuxOutput extends Tmux $this->pdo->log->alternateOver("%-20s") . " " . $this->pdo->log->tmuxOrange("%-33.33s"); $this->_colourMasks[2.1] = $this->pdo->log->headerOver("%-20s") . " " . $this->pdo->log->tmuxOrange("%-33.33s"); - $this->_colourMasks[3] = $this->pdo->log->header("%-16.16s %25.25s %25.25s");; + $this->_colourMasks[3] = $this->pdo->log->header("%-16.16s %25.25s %25.25s"); ; $this->_colourMasks[4] = $this->pdo->log->primaryOver("%-16.16s") . - " " . $this->pdo->log->tmuxOrange("%25.25s %25.25s");; + " " . $this->pdo->log->tmuxOrange("%25.25s %25.25s"); ; $this->_colourMasks[5] = $this->pdo->log->tmuxOrange("%-16.16s %25.25s %25.25s"); } } \ No newline at end of file diff --git a/lib/copy_this/www/lib/TmuxRun.php b/lib/copy_this/www/lib/TmuxRun.php index 7fa82c042..dd6a9601a 100644 --- a/lib/copy_this/www/lib/TmuxRun.php +++ b/lib/copy_this/www/lib/TmuxRun.php @@ -24,9 +24,9 @@ class TmuxRun extends Tmux // main switch for running tmux panes public function runPane($cmdParam, &$runVar) { - switch ((int) $runVar['constants']['sequential']) { + switch ((int)$runVar['constants']['sequential']) { case 0: - switch ((string) $cmdParam) { + switch ((string)$cmdParam) { case 'amazon': $this->_runAmazon($runVar); break; @@ -194,7 +194,7 @@ class TmuxRun extends Tmux || $runVar['counts']['now']['processbooks'] > 0 || $runVar['counts']['now']['processconsole'] > 0 || $runVar['counts']['now']['processgames'] > 0 || $runVar['counts']['now']['processxxx'] > 0) && ($runVar['settings']['processbooks'] == 1 || $runVar['settings']['processmusic'] == 1 - || $runVar['settings']['processgames'] == 1 || $runVar['settings']['processxxx'] == 1): + || $runVar['settings']['processgames'] == 1 || $runVar['settings']['processxxx'] == 1): $log = $this->writelog($runVar['panes']['two'][2]); shell_exec("tmux respawnp -t{$runVar['constants']['tmux_session']}:2.2 ' \ diff --git a/lib/copy_this/www/lib/XXX.php b/lib/copy_this/www/lib/XXX.php index e1c192cfa..96d3e8abd 100644 --- a/lib/copy_this/www/lib/XXX.php +++ b/lib/copy_this/www/lib/XXX.php @@ -258,7 +258,7 @@ class XXX /** * Order types for xxx page. * - * @return array + * @return string[] */ public function getXXXOrdering() { @@ -306,8 +306,8 @@ class XXX $newArr = array(); $i = 0; foreach ($tmpArr as $ta) { - if ($field == "genre" ) { - $ta = $this->getGenres(true,$ta); + if ($field == "genre") { + $ta = $this->getGenres(true, $ta); $ta = $ta["title"]; } if ($i > 7) { @@ -340,8 +340,7 @@ class XXX public function update( $id = '', $title = '', $tagLine = '', $plot = '', $genre = '', $director = '', $actors = '', $extras = '', $productInfo = '', $trailers = '', $directUrl = '', $classUsed = '', $cover = '', $backdrop = '' - ) - { + ) { if (!empty($id)) { $this->pdo->queryExec( @@ -371,7 +370,7 @@ class XXX /** * Fetch xxx info for the movie. * - * @param $xxxmovie + * @param string $xxxmovie * * @return bool */ @@ -386,7 +385,7 @@ class XXX if ($iafd->findme() !== false) { - switch($iafd->classUsed) { + switch ($iafd->classUsed) { case "ade": $mov = new \ADE(); $mov->directLink = (string)$iafd->directUrl; @@ -479,22 +478,22 @@ class XXX $mov['directurl'] = html_entity_decode($res['directurl'], ENT_QUOTES, 'UTF-8'); $mov['classused'] = $this->whichclass; - $check = $this->pdo->queryOneRow(sprintf('SELECT id FROM xxxinfo WHERE title = %s', $this->pdo->escapeString($mov['title']))); + $check = $this->pdo->queryOneRow(sprintf('SELECT id FROM xxxinfo WHERE title = %s', $this->pdo->escapeString($mov['title']))); $xxxID = 0; - if(isset($check['id'])){ + if (isset($check['id'])) { $xxxID = $check['id']; } - if($check === false OR $xxxID > 0){ + if ($check === false OR $xxxID > 0) { // Update Current XXX Information - getXXXCovers.php - if($xxxID > 0){ + if ($xxxID > 0) { $this->update($check['id'], $mov['title'], $mov['tagline'], $mov['plot'], $mov['genre'], $mov['director'], $mov['actors'], $mov['extras'], $mov['productinfo'], $mov['trailers'], $mov['directurl'], $mov['classused']); $xxxID = $check['id']; } // Insert New XXX Information - if($check === false){ + if ($check === false) { $xxxID = $this->pdo->queryInsert( sprintf(" INSERT INTO xxxinfo @@ -605,13 +604,13 @@ class XXX /** * Checks xxxinfo to make sure releases exist * - * @param $releaseName + * @param string $releaseName * * @return array|bool */ protected function checkXXXInfoExists($releaseName) { - return $this->pdo->queryOneRow(sprintf("SELECT id, title FROM xxxinfo WHERE title LIKE %s", "'". $releaseName . "%'")); + return $this->pdo->queryOneRow(sprintf("SELECT id, title FROM xxxinfo WHERE title LIKE %s", "'" . $releaseName . "%'")); } /** @@ -645,7 +644,7 @@ class XXX $name = trim(preg_replace('/(brazilian|chinese|croatian|danish|deutsch|dutch|estonian|flemish|finnish|french|german|greek|hebrew|icelandic|italian|latin|nordic|norwegian|polish|portuguese|japenese|japanese|russian|serbian|slovenian|spanish|spanisch|swedish|thai|turkish)$/i', '', $name)); // Check if the name is long enough and not just numbers and not file (d) of (d) and does not contain Episodes and any dated 00.00.00 which are site rips.. - if (strlen($name) > 5 && !preg_match('/^\d+$/', $name) && !preg_match('/( File \d+ of \d+|\d+.\d+.\d+)/',$name) && !preg_match('/(E\d+)/',$name) && !preg_match('/\d\d\.\d\d.\d\d/', $name)) { + if (strlen($name) > 5 && !preg_match('/^\d+$/', $name) && !preg_match('/( File \d+ of \d+|\d+.\d+.\d+)/', $name) && !preg_match('/(E\d+)/', $name) && !preg_match('/\d\d\.\d\d.\d\d/', $name)) { $this->currentTitle = $name; return true; } else { @@ -663,7 +662,8 @@ class XXX * * @return array|null */ - public function getAllGenres($activeOnly = false) { + public function getAllGenres($activeOnly = false) + { $res = $ret = null; if ($activeOnly) { @@ -689,7 +689,7 @@ class XXX public function getGenres($activeOnly = false, $gid = null) { if (isset($gid)) { - $gid = " AND id = ". $this->pdo->escapeString($gid) . " ORDER BY title"; + $gid = " AND id = " . $this->pdo->escapeString($gid) . " ORDER BY title"; } else { $gid = " ORDER BY title"; } @@ -728,7 +728,7 @@ class XXX } } - $ret = ltrim($ret,","); + $ret = ltrim($ret, ","); return ($ret); } @@ -743,7 +743,7 @@ class XXX { $res = ''; if (isset($genre)) { - $res = $this->pdo->queryInsert(sprintf("INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)",$this->pdo->escapeString($genre), 6000, 0)); + $res = $this->pdo->queryInsert(sprintf("INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)", $this->pdo->escapeString($genre), 6000, 0)); } return $res; } @@ -762,7 +762,7 @@ class XXX if ($whichclass === "ade") { if (!empty($res)) { $trailers = unserialize($res); - $ret .=""; + $ret .= ""; $ret .= ""; $ret .= ""; @@ -773,7 +773,7 @@ class XXX if (!empty($res)) { $trailers = unserialize($res); $ret .= ""; return ($ret); diff --git a/lib/copy_this/www/lib/adminpage.php b/lib/copy_this/www/lib/adminpage.php index 81b2a94cc..8030ea5b3 100644 --- a/lib/copy_this/www/lib/adminpage.php +++ b/lib/copy_this/www/lib/adminpage.php @@ -7,32 +7,34 @@ require_once(WWW_DIR . "/lib/users.php"); * All admin pages implement this class. Enforces admin role for requesting user. */ class AdminPage extends BasePage -{ +{ /** * Default constructor. */ function AdminPage() - { + { parent::BasePage(); $tplpaths = array(); - if ($this->site->style != "default") - $tplpaths["style_admin"] = WWW_DIR . 'templates/' . $this->site->style . '/views/admin'; + if ($this->site->style != "default") { + $tplpaths["style_admin"] = WWW_DIR . 'templates/' . $this->site->style . '/views/admin'; + } $tplpaths["admin"] = WWW_DIR . 'templates/default/views/admin'; $tplpaths["frontend"] = WWW_DIR . 'templates/default/views/frontend'; $this->smarty->setTemplateDir($tplpaths); $users = new Users(); - if (!$users->isLoggedIn() || !isset($this->userdata["role"]) || $this->userdata["role"] != Users::ROLE_ADMIN) - $this->show403(true); + if (!$users->isLoggedIn() || !isset($this->userdata["role"]) || $this->userdata["role"] != Users::ROLE_ADMIN) { + $this->show403(true); + } } /** * Output a page using the admin template. */ - public function render() - { + public function render() + { $this->smarty->assign('page', $this); $admin_menu = $this->smarty->fetch('adminmenu.tpl'); diff --git a/lib/copy_this/www/lib/amazon.php b/lib/copy_this/www/lib/amazon.php index af500a604..8ed93d765 100644 --- a/lib/copy_this/www/lib/amazon.php +++ b/lib/copy_this/www/lib/amazon.php @@ -129,8 +129,7 @@ class AmazonProductAPI $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD", "NODE"); $allowedCategories = array("Music", "DVD", "VideoGames", "MP3Downloads"); - switch ($searchType) - { + switch ($searchType) { case "UPC" : $parameters = array("Operation" => "ItemLookup", "ItemId" => $search, "SearchIndex" => $category, diff --git a/lib/copy_this/www/lib/book.php b/lib/copy_this/www/lib/book.php index ec9063813..6a724cc2d 100644 --- a/lib/copy_this/www/lib/book.php +++ b/lib/copy_this/www/lib/book.php @@ -53,10 +53,11 @@ class Book { $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } return $db->query(" SELECT * FROM bookinfo ORDER BY createddate DESC" . $limit); } @@ -101,14 +102,16 @@ class Book $browseby = $this->getBrowseBy(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + if ($maxage > 0) { + $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } $order = $this->getBrowseOrder($orderby); $sql = sprintf(" SELECT r.bookinfoid, max(postdate), b.* from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s group by r.bookinfoid order by %s %s" . $limit, $browseby, $maxagesql, $order[0], $order[1]); @@ -118,11 +121,11 @@ class Book //get a copy of all the bookinfoids // $ids = ""; - foreach ($rows as $row) - $ids .= $row["bookinfoid"] . ", "; + foreach ($rows as $row) { + $ids .= $row["bookinfoid"] . ", "; + } - if (strlen($ids) > 0) - { + if (strlen($ids) > 0) { $ids = substr($ids, 0, -2); // @@ -264,8 +267,7 @@ class Book $mus = array(); $amaz = $this->fetchAmazonProperties($author . " " . $title); - if (!$amaz) - { + if (!$amaz) { //echo "tried to lookup ".$author." ".$title; return false; } @@ -278,10 +280,11 @@ class Book $item["asin"] = (string)$amaz->Items->Item->ASIN; $item["url"] = (string)$amaz->Items->Item->DetailPageURL; $item["coverurl"] = (string)$amaz->Items->Item->LargeImage->URL; - if ($item['coverurl'] != "") - $item['cover'] = 1; - else - $item['cover'] = 0; + if ($item['coverurl'] != "") { + $item['cover'] = 1; + } else { + $item['cover'] = 0; + } $item["author"] = (string)$amaz->Items->Item->ItemAttributes->Author; $item["dewey"] = (string)$amaz->Items->Item->ItemAttributes->DeweyDecimalNumber; $item["ean"] = (string)$amaz->Items->Item->ItemAttributes->EAN; @@ -291,8 +294,9 @@ class Book $item["pages"] = (string)$amaz->Items->Item->ItemAttributes->NumberOfPages; $item["title"] = (string)$amaz->Items->Item->ItemAttributes->Title; $item["review"] = ""; - if (isset($amaz->Items->Item->EditorialReviews)) - $item["review"] = trim(strip_tags((string)$amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + if (isset($amaz->Items->Item->EditorialReviews)) { + $item["review"] = trim(strip_tags((string)$amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + } //This is to verify the result back from amazon was at least somewhat related to what was intended. //If you are debugging releases comment out the following code to show all info @@ -344,12 +348,9 @@ class Book public function fetchAmazonProperties($title) { $obj = new AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag); - try - { + try { $result = $obj->searchProducts($title, AmazonProductAPI::BOOKS, "TITLE"); - } - catch (Exception $e) - { + } catch (Exception $e) { $result = false; } @@ -366,40 +367,36 @@ class Book $numlookedup = 0; $res = $db->queryDirect(sprintf("SELECT searchname, id from releases where bookinfoid IS NULL and categoryid = %d ORDER BY postdate DESC LIMIT 100", Category::CAT_BOOK_EBOOK)); - if ($db->getNumRows($res) > 0) - { - if ($this->echooutput) - echo "BookPrc : Processing " . $db->getNumRows($res) . " book releases\n"; + if ($db->getNumRows($res) > 0) { + if ($this->echooutput) { + echo "BookPrc : Processing " . $db->getNumRows($res) . " book releases\n"; + } - while ($arr = $db->getAssocArray($res)) - { - if ($numlookedup > Book::NUMTOPROCESSPERTIME) - return; + while ($arr = $db->getAssocArray($res)) { + if ($numlookedup > Book::NUMTOPROCESSPERTIME) { + return; + } $bookId = -2; $book = $this->parseAuthor($arr['searchname']); - if ($book !== false) - { - if ($this->echooutput) - echo 'BookPrc : ' . $book["author"] . ' - ' . $book["title"] . "\n"; + if ($book !== false) { + if ($this->echooutput) { + echo 'BookPrc : ' . $book["author"] . ' - ' . $book["title"] . "\n"; + } //check for existing book entry $bookCheck = $this->getBookInfoByName($book["author"], $book["title"]); - if ($bookCheck === false) - { + if ($bookCheck === false) { // // get from amazon // $numlookedup++; $ret = $this->updateBookInfo($book["author"], $book["title"]); - if ($ret !== false) - { + if ($ret !== false) { $bookId = $ret; } - } - else - { + } else { $bookId = $bookCheck["id"]; } } @@ -456,11 +453,9 @@ class Book // switch Cratchett, Bob to Bob Cratchett preg_match_all('/[,]/i', $result['author'], $matches); - if (sizeof($matches[0]) == 1) - { + if (sizeof($matches[0]) == 1) { $pos = strpos($result['author'], ","); - if ($pos !== false) - { + if ($pos !== false) { $firstname = substr($result['author'], $pos + 1); $surname = substr($result['author'], 0, $pos); $result['author'] = trim($firstname . " " . $surname); @@ -479,19 +474,21 @@ class Book { $db = new DB(); - if ($pages == 0) - $pages = "null"; - else - $pages = $pages + 0; + if ($pages == 0) { + $pages = "null"; + } else { + $pages = $pages + 0; + } - if ($publishdate == "") - $publishdate = "null"; - elseif (strlen($publishdate) == 4) - $publishdate = $db->escapeString($publishdate . "-01-01"); - elseif (strlen($publishdate) == 7) - $publishdate = $db->escapeString($publishdate . "-01"); - else - $publishdate = $db->escapeString($publishdate); + if ($publishdate == "") { + $publishdate = "null"; + } elseif (strlen($publishdate) == 4) { + $publishdate = $db->escapeString($publishdate . "-01-01"); + } elseif (strlen($publishdate) == 7) { + $publishdate = $db->escapeString($publishdate . "-01"); + } else { + $publishdate = $db->escapeString($publishdate); + } $sql = sprintf("INSERT INTO bookinfo (title, asin, url, author, publisher, publishdate, review, cover, createddate, updateddate, dewey, ean, isbn, pages) VALUES (%s, %s, %s, %s, %s, %s, %s, %d, now(), now(), %s, %s, %s, %s) diff --git a/lib/copy_this/www/lib/category.php b/lib/copy_this/www/lib/category.php index db8ae4067..93a305db1 100644 --- a/lib/copy_this/www/lib/category.php +++ b/lib/copy_this/www/lib/category.php @@ -277,8 +277,9 @@ class Category $arr = $db->query(sprintf("select * from category where status = %d %s", Category::STATUS_ACTIVE, $exccatlist), true); foreach ($arr as $a) { - if ($a["parentid"] == "") - $ret[] = $a; + if ($a["parentid"] == "") { + $ret[] = $a; + } } foreach ($ret as $key => $parent) { diff --git a/lib/copy_this/www/lib/console.php b/lib/copy_this/www/lib/console.php index ab31f4eb8..44e8e2858 100644 --- a/lib/copy_this/www/lib/console.php +++ b/lib/copy_this/www/lib/console.php @@ -55,10 +55,11 @@ class Console { $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } return $db->query(" SELECT * FROM consoleinfo ORDER BY createddate DESC" . $limit); } @@ -83,26 +84,22 @@ class Console $browseby = $this->getBrowseBy(); $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { + if (count($cat) > 0 && $cat[0] != -1) { $catsrch = " ("; - foreach ($cat as $category) - { - if ($category != -1) - { + foreach ($cat as $category) { + if ($category != -1) { $categ = new Category(); - if ($categ->isParent($category)) - { + if ($categ->isParent($category)) { $children = $categ->getChildren($category); $chlist = "-99"; - foreach ($children as $child) - $chlist .= ", " . $child["id"]; + foreach ($children as $child) { + $chlist .= ", " . $child["id"]; + } - if ($chlist != "-99") - $catsrch .= " r.categoryid in (" . $chlist . ") or "; - } - else - { + if ($chlist != "-99") { + $catsrch .= " r.categoryid in (" . $chlist . ") or "; + } + } else { $catsrch .= sprintf(" r.categoryid = %d or ", $category); } } @@ -110,14 +107,16 @@ class Console $catsrch .= "1=2 )"; } - if ($maxage > 0) - $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; + if ($maxage > 0) { + $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } else { + $maxage = ""; + } $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + if (count($excludedcats) > 0) { + $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + } $sql = sprintf("select count(r.id) as num from releases r inner join consoleinfo con on con.id = r.consoleinfoid and con.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist); $res = $db->queryOneRow($sql, true); @@ -133,32 +132,29 @@ class Console $browseby = $this->getBrowseBy(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { + if (count($cat) > 0 && $cat[0] != -1) { $catsrch = " ("; - foreach ($cat as $category) - { - if ($category != -1) - { + foreach ($cat as $category) { + if ($category != -1) { $categ = new Category(); - if ($categ->isParent($category)) - { + if ($categ->isParent($category)) { $children = $categ->getChildren($category); $chlist = "-99"; - foreach ($children as $child) - $chlist .= ", " . $child["id"]; + foreach ($children as $child) { + $chlist .= ", " . $child["id"]; + } - if ($chlist != "-99") - $catsrch .= " r.categoryid in (" . $chlist . ") or "; - } - else - { + if ($chlist != "-99") { + $catsrch .= " r.categoryid in (" . $chlist . ") or "; + } + } else { $catsrch .= sprintf(" r.categoryid = %d or ", $category); } } @@ -167,12 +163,14 @@ class Console } $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + if ($maxage > 0) { + $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + if (count($excludedcats) > 0) { + $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + } $order = $this->getConsoleOrder($orderby); $sql = sprintf(" SELECT r.*, r.id as releaseid, con.*, g.title as genre, groups.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.id, ',', c.id) as category_ids, rn.id as nfoid from releases r left outer join groups on groups.id = r.groupid inner join consoleinfo con on con.id = r.consoleinfoid left outer join releasenfo rn on rn.releaseid = r.id and rn.nfo is not null left outer join category c on c.id = r.categoryid left outer join category cp on cp.id = c.parentid left outer join genres g on g.id = con.genreID where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s order by %s %s" . $limit, $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1]); @@ -288,70 +286,62 @@ class Console // get game properties // $con['coverurl'] = (string)$amaz->Items->Item->LargeImage->URL; - if ($con['coverurl'] != "") - $con['cover'] = 1; - else - $con['cover'] = 0; + if ($con['coverurl'] != "") { + $con['cover'] = 1; + } else { + $con['cover'] = 0; + } $con['title'] = (string)$amaz->Items->Item->ItemAttributes->Title; - if (empty($con['title'])) - $con['title'] = $gameInfo['title']; + if (empty($con['title'])) { + $con['title'] = $gameInfo['title']; + } $con['platform'] = (string)$amaz->Items->Item->ItemAttributes->Platform; - if (empty($con['platform'])) - $con['platform'] = $gameInfo['platform']; + if (empty($con['platform'])) { + $con['platform'] = $gameInfo['platform']; + } //Beginning of Recheck Code //This is to verify the result back from amazon was at least somewhat related to what was intended. //Some of the Platforms don't match Amazon's exactly. This code is needed to facilitate rechecking. - if (preg_match('/^X360$/i', $gameInfo['platform'])) - { + if (preg_match('/^X360$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('X360', 'Xbox 360', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^XBOX360$/i', $gameInfo['platform'])) - { + if (preg_match('/^XBOX360$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('XBOX360', 'Xbox 360', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^NDS$/i', $gameInfo['platform'])) - { + if (preg_match('/^NDS$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('NDS', 'Nintendo DS', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^PS3$/i', $gameInfo['platform'])) - { + if (preg_match('/^PS3$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('PS3', 'PlayStation 3', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^PSP$/i', $gameInfo['platform'])) - { + if (preg_match('/^PSP$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('PSP', 'Sony PSP', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^Wii$/i', $gameInfo['platform'])) - { + if (preg_match('/^Wii$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('Wii', 'Nintendo Wii', $gameInfo['platform']); // baseline single quote $gameInfo['platform'] = str_replace('WII', 'Nintendo Wii', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^N64$/i', $gameInfo['platform'])) - { + if (preg_match('/^N64$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('N64', 'Nintendo 64', $gameInfo['platform']); // baseline single quote } - if (preg_match('/^NES$/i', $gameInfo['platform'])) - { + if (preg_match('/^NES$/i', $gameInfo['platform'])) { $gameInfo['platform'] = str_replace('NES', 'Nintendo NES', $gameInfo['platform']); // baseline single quote } - if (preg_match('/Super/i', $con['platform'])) - { + if (preg_match('/Super/i', $con['platform'])) { $con['platform'] = str_replace('Super Nintendo', 'SNES', $con['platform']); // baseline single quote $con['platform'] = str_replace('Nintendo Super NES', 'SNES', $con['platform']); // baseline single quote } //Remove Online Game Code So Titles Match Properly. - if (preg_match('/\[Online Game Code\]/i', $con['title'])) - { + if (preg_match('/\[Online Game Code\]/i', $con['title'])) { $con['title'] = str_replace(' [Online Game Code]', '', $con['title']); // baseline single quote } //Basically the XBLA names contain crap, this is to reduce the title down far enough to be usable - if (preg_match('/xbla/i', $gameInfo['platform'])) - { + if (preg_match('/xbla/i', $gameInfo['platform'])) { $gameInfo['title'] = substr($gameInfo['title'], 0, 10); $con['substr'] = $gameInfo['title']; } @@ -382,60 +372,58 @@ class Console //echo("Matched: Platform Percentage: $platformpercent%"); //If the Title is less than 80% Platform must be 100% unless it is XBLA - if ($titlepercent < 70) - { - if ($platformpercent != 100) - { + if ($titlepercent < 70) { + if ($platformpercent != 100) { return false; } } //If title is less than 80% then its most likely not a match - if ($titlepercent < 70) - return false; + if ($titlepercent < 70) { + return false; + } //Platform must equal 100% - if ($platformpercent != 100) - return false; + if ($platformpercent != 100) { + return false; + } $con['asin'] = (string)$amaz->Items->Item->ASIN; $con['url'] = (string)$amaz->Items->Item->DetailPageURL; $con['salesrank'] = (string)$amaz->Items->Item->SalesRank; - if ($con['salesrank'] == "") - $con['salesrank'] = 'null'; + if ($con['salesrank'] == "") { + $con['salesrank'] = 'null'; + } $con['publisher'] = (string)$amaz->Items->Item->ItemAttributes->Publisher; $con['esrb'] = (string)$amaz->Items->Item->ItemAttributes->ESRBAgeRating; $con['releasedate'] = $db->escapeString((string)$amaz->Items->Item->ItemAttributes->ReleaseDate); - if ($con['releasedate'] == "''") - $con['releasedate'] = 'null'; + if ($con['releasedate'] == "''") { + $con['releasedate'] = 'null'; + } $con['review'] = ""; - if (isset($amaz->Items->Item->EditorialReviews)) - $con['review'] = trim(strip_tags((string)$amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + if (isset($amaz->Items->Item->EditorialReviews)) { + $con['review'] = trim(strip_tags((string)$amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + } $genreKey = -1; $genreName = ''; - if (isset($amaz->Items->Item->BrowseNodes) || isset($amaz->Items->Item->ItemAttributes->Genre)) - { - if (isset($amaz->Items->Item->BrowseNodes)) - { + if (isset($amaz->Items->Item->BrowseNodes) || isset($amaz->Items->Item->ItemAttributes->Genre)) { + if (isset($amaz->Items->Item->BrowseNodes)) { //had issues getting this out of the browsenodes obj //workaround is to get the xml and load that into its own obj $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml(); $amazGenresObj = simplexml_load_string($amazGenresXml); $amazGenres = $amazGenresObj->xpath("//Name"); - foreach ($amazGenres as $amazGenre) - { + foreach ($amazGenres as $amazGenre) { $currName = trim($amazGenre[0]); - if (empty($genreName)) - { + if (empty($genreName)) { $genreMatch = $this->matchBrowseNode($currName); - if ($genreMatch !== false) - { + if ($genreMatch !== false) { $genreName = $genreMatch; break; } @@ -443,16 +431,13 @@ class Console } } - if (empty($genreName) && isset($amaz->Items->Item->ItemAttributes->Genre)) - { + if (empty($genreName) && isset($amaz->Items->Item->ItemAttributes->Genre)) { $tmpGenre = (string)$amaz->Items->Item->ItemAttributes->Genre; $tmpGenre = str_replace('-', ' ', $tmpGenre); $tmpGenre = explode(' ', $tmpGenre); - foreach ($tmpGenre as $tg) - { + foreach ($tmpGenre as $tg) { $genreMatch = $this->matchBrowseNode(ucwords($tg)); - if ($genreMatch !== false) - { + if ($genreMatch !== false) { $genreName = $genreMatch; break; } @@ -498,12 +483,9 @@ class Console public function fetchAmazonProperties($title, $node) { $obj = new AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag); - try - { + try { $result = $obj->searchProducts($title, AmazonProductAPI::GAMES, "NODE", $node); - } - catch (Exception $e) - { + } catch (Exception $e) { $result = false; } return $result; @@ -519,45 +501,40 @@ class Console $numlookedup = 0; $res = $db->queryDirect(sprintf("SELECT searchname, id from releases where consoleinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 100", Category::CAT_PARENT_GAME)); - if ($db->getNumRows($res) > 0) - { - if ($this->echooutput) - echo "ConsPrc : Processing " . $db->getNumRows($res) . " console releases\n"; + if ($db->getNumRows($res) > 0) { + if ($this->echooutput) { + echo "ConsPrc : Processing " . $db->getNumRows($res) . " console releases\n"; + } - while ($arr = $db->getAssocArray($res)) - { - if ($numlookedup > Console::NUMTOPROCESSPERTIME) - return; + while ($arr = $db->getAssocArray($res)) { + if ($numlookedup > Console::NUMTOPROCESSPERTIME) { + return; + } $gameInfo = $this->parseTitle($arr['searchname']); - if ($gameInfo !== false) - { + if ($gameInfo !== false) { - if ($this->echooutput) - echo 'ConsPrc : ' . $gameInfo["title"] . ' (' . $gameInfo["platform"] . ')' . "\n"; + if ($this->echooutput) { + echo 'ConsPrc : ' . $gameInfo["title"] . ' (' . $gameInfo["platform"] . ')' . "\n"; + } //check for existing console entry $gameCheck = $this->getConsoleInfoByName($gameInfo["title"], $gameInfo["platform"]); - if ($gameCheck === false) - { + if ($gameCheck === false) { $numlookedup++; $gameId = $this->updateConsoleInfo($gameInfo); - if ($gameId === false) - { + if ($gameId === false) { $gameId = -2; } - } - else - { + } else { $gameId = $gameCheck["id"]; } //update release $db->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", $gameId, $arr["id"])); - } - else { + } else { //could not parse release title $db->queryExec(sprintf("update releases SET consoleinfoid = %d WHERE id = %d", -2, $arr["id"])); } @@ -595,13 +572,10 @@ class Console //get the platform of the release preg_match('/[\.\-_ ](?PXBLA|WiiWARE|N64|SNES|NES|PS2|PS3|PS 3|PSP|WII|XBOX360|X\-?BOX|X360|NDS|NGC)/i', $releasename, $matches); - if (isset($matches['platform'])) - { + if (isset($matches['platform'])) { $platform = $matches['platform']; - if (preg_match('/^(XBLA)$/i', $platform)) - { - if (preg_match('/DLC/i', $title)) - { + if (preg_match('/^(XBLA)$/i', $platform)) { + if (preg_match('/DLC/i', $title)) { $platform = str_replace('XBLA', 'XBOX360', $platform); // baseline single quote } } @@ -623,8 +597,7 @@ class Console */ function getBrowseNode($platform) { - switch ($platform) - { + switch ($platform) { case 'PS2': $nodeId = '301712'; break; @@ -677,8 +650,7 @@ class Console { $str = ''; - switch ($nodeName) - { + switch ($nodeName) { case 'Action': case 'Adventure': case 'Arcade': diff --git a/lib/copy_this/www/lib/content.php b/lib/copy_this/www/lib/content.php index 4b4dd68b7..08771ff3c 100644 --- a/lib/copy_this/www/lib/content.php +++ b/lib/copy_this/www/lib/content.php @@ -17,13 +17,11 @@ class Contents */ public function validate($content) { - if (substr($content["url"], 0, 1) != '/') - { + if (substr($content["url"], 0, 1) != '/') { $content["url"] = "/" . $content["url"]; } - if (substr($content["url"], strlen($content["url"]) - 1) != '/') - { + if (substr($content["url"], strlen($content["url"]) - 1) != '/') { $content["url"] = $content["url"] . "/"; } diff --git a/lib/copy_this/www/lib/episode.php b/lib/copy_this/www/lib/episode.php index 689ba44f1..090a20936 100644 --- a/lib/copy_this/www/lib/episode.php +++ b/lib/copy_this/www/lib/episode.php @@ -22,11 +22,16 @@ class Episode { $db = new DB(); - if ($epabsolute == '0') //as string - not int. + if ($epabsolute == '0') { + //as string - not int. if (!preg_match('/[21]\d{3}\/\d{2}\/\d{2}/', $fullep)) $additionalSql = sprintf('AND fullep = %s', $db->escapeString($fullep)); - else $additionalSql = sprintf('AND airdate LIKE %s', $db->escapeString($fullep . ' %')); - else $additionalSql = sprintf('AND epabsolute = %s', $db->escapeString($epabsolute)); + } else { + $additionalSql = sprintf('AND airdate LIKE %s', $db->escapeString($fullep . ' %')); + } + else { + $additionalSql = sprintf('AND epabsolute = %s', $db->escapeString($epabsolute)); + } return $db->queryOneRow(sprintf('SELECT * FROM episodeinfo WHERE showtitle = %s %s', $db->escapeString($showtitle), $additionalSql)); } diff --git a/lib/copy_this/www/lib/forum.php b/lib/copy_this/www/lib/forum.php index b28fd19a2..6347dae57 100644 --- a/lib/copy_this/www/lib/forum.php +++ b/lib/copy_this/www/lib/forum.php @@ -84,10 +84,11 @@ class Forum { $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } return $db->query(sprintf(" SELECT forumpost.*, users.username from forumpost left outer join users on users.id = forumpost.userid where parentid = 0 order by updateddate desc" . $limit)); } @@ -143,10 +144,11 @@ class Forum { $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } return $db->query(sprintf(" SELECT forumpost.*, users.username FROM forumpost LEFT OUTER JOIN users ON users.id = forumpost.userid where userid = %d order by forumpost.createddate desc " . $limit, $uid)); } diff --git a/lib/copy_this/www/lib/framework/basepage.php b/lib/copy_this/www/lib/framework/basepage.php index 41e37d947..6b3d91a1e 100644 --- a/lib/copy_this/www/lib/framework/basepage.php +++ b/lib/copy_this/www/lib/framework/basepage.php @@ -42,12 +42,19 @@ class BasePage $this->floodCheck(); } - if ((function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) || ini_get('magic_quotes_sybase')) - { - foreach ($_GET as $k => $v) $_GET[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); - foreach ($_POST as $k => $v) $_POST[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); - foreach ($_REQUEST as $k => $v) $_REQUEST[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); - foreach ($_COOKIE as $k => $v) $_COOKIE[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); + if ((function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) || ini_get('magic_quotes_sybase')) { + foreach ($_GET as $k => $v) { + $_GET[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); + } + foreach ($_POST as $k => $v) { + $_POST[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); + } + foreach ($_REQUEST as $k => $v) { + $_REQUEST[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); + } + foreach ($_COOKIE as $k => $v) { + $_COOKIE[$k] = (is_array($v)) ? array_map("stripslashes", $v) : stripslashes($v); + } } // set site variable @@ -58,8 +65,9 @@ class BasePage $this->settings = new DB(); $this->smarty = new Smarty(); - if ($this->site->style != "default") - $this->smarty->addTemplateDir(WWW_DIR . 'templates/' . $this->site->style . '/views/frontend', 'style_frontend'); + if ($this->site->style != "default") { + $this->smarty->addTemplateDir(WWW_DIR . 'templates/' . $this->site->style . '/views/frontend', 'style_frontend'); + } $this->smarty->addTemplateDir(WWW_DIR . 'templates/default/views/frontend', 'frontend'); $this->smarty->setCompileDir(SMARTY_DIR . 'templates_c' . DIRECTORY_SEPARATOR); $this->smarty->setConfigDir(SMARTY_DIR . 'configs' . DIRECTORY_SEPARATOR); @@ -67,18 +75,19 @@ class BasePage $this->smarty->error_reporting = (E_ALL - E_NOTICE); $this->secure_connection = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)); - if (file_exists(WWW_DIR . 'templates/' . $this->site->style . '/theme.php')) - require_once(WWW_DIR . 'templates/' . $this->site->style . '/theme.php'); + if (file_exists(WWW_DIR . 'templates/' . $this->site->style . '/theme.php')) { + require_once(WWW_DIR . 'templates/' . $this->site->style . '/theme.php'); + } $this->smarty->assign('themevars', (isset($themevars) ? $themevars : null)); $servername = null; - if (defined('EXTERNAL_PROXY_IP') && defined('EXTERNAL_HOST_NAME') && isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == EXTERNAL_PROXY_IP) - $servername = EXTERNAL_HOST_NAME; - elseif (isset($_SERVER["SERVER_NAME"])) - $servername = $_SERVER["SERVER_NAME"]; + if (defined('EXTERNAL_PROXY_IP') && defined('EXTERNAL_HOST_NAME') && isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == EXTERNAL_PROXY_IP) { + $servername = EXTERNAL_HOST_NAME; + } elseif (isset($_SERVER["SERVER_NAME"])) { + $servername = $_SERVER["SERVER_NAME"]; + } - if ($servername != "") - { + if ($servername != "") { $this->serverurl = ($this->secure_connection ? "https://" : "http://") . $servername . (($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") ? ":" . $_SERVER["SERVER_PORT"] : "") . WWW_TOP . '/'; $this->smarty->assign('serverroot', $this->serverurl); } @@ -100,35 +109,34 @@ class BasePage $this->userdata["categoryexclusions"] = $users->getCategoryExclusion($users->currentUserId()); //update lastlogin every 15 mins - if (strtotime($this->userdata['now']) - 900 > strtotime($this->userdata['lastlogin'])) - $users->updateSiteAccessed($this->userdata['id']); + if (strtotime($this->userdata['now']) - 900 > strtotime($this->userdata['lastlogin'])) { + $users->updateSiteAccessed($this->userdata['id']); + } $this->smarty->assign('userdata', $this->userdata); $this->smarty->assign('loggedin', "true"); - if (!empty($this->userdata['nzbvortex_api_key']) && (!empty($this->userdata['nzbvortex_server_url']))) - $this->smarty->assign('weHasVortex', true); + if (!empty($this->userdata['nzbvortex_api_key']) && (!empty($this->userdata['nzbvortex_server_url']))) { + $this->smarty->assign('weHasVortex', true); + } $sab = new SABnzbd($this); - if ($sab->integrated !== false && $sab->url != '' && $sab->apikey != '') - { + if ($sab->integrated !== false && $sab->url != '' && $sab->apikey != '') { $this->smarty->assign('sabintegrated', $sab->integrated); $this->smarty->assign('sabapikeytype', $sab->apikeytype); } - if ($this->userdata["role"] == Users::ROLE_ADMIN) - $this->smarty->assign('isadmin', "true"); + if ($this->userdata["role"] == Users::ROLE_ADMIN) { + $this->smarty->assign('isadmin', "true"); + } - if ($this->userdata["hideads"] == "1") - { + if ($this->userdata["hideads"] == "1") { $this->site->adheader = ""; $this->site->adbrowse = ""; $this->site->addetail = ""; } $this->floodCheck($this->userdata["role"]); - } - else - { + } else { $this->smarty->assign('isadmin', "false"); $this->smarty->assign('loggedin', "false"); $this->floodCheck(); @@ -224,8 +232,9 @@ class BasePage { header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); - if ($retry != '') - header('Retry-After: ' . $retry); + if ($retry != '') { + header('Retry-After: ' . $retry); + } echo " @@ -246,8 +255,9 @@ class BasePage public function show429($retry = '') { header('HTTP/1.1 429 Too Many Requests'); - if ($retry != '') - header('Retry-After: ' . $retry); + if ($retry != '') { + header('Retry-After: ' . $retry); + } echo " diff --git a/lib/copy_this/www/lib/menu.php b/lib/copy_this/www/lib/menu.php index 61eb721b1..2d5e411ad 100644 --- a/lib/copy_this/www/lib/menu.php +++ b/lib/copy_this/www/lib/menu.php @@ -15,26 +15,24 @@ class Menu $db = new DB(); $guest = ""; - if ($role != Users::ROLE_GUEST) - $guest = sprintf(" and role != %d ", Users::ROLE_GUEST); + if ($role != Users::ROLE_GUEST) { + $guest = sprintf(" and role != %d ", Users::ROLE_GUEST); + } - if ($role != Users::ROLE_ADMIN) - $guest .= sprintf(" and role != %d ", Users::ROLE_ADMIN); + if ($role != Users::ROLE_ADMIN) { + $guest .= sprintf(" and role != %d ", Users::ROLE_ADMIN); + } $sql = sprintf("select * from menu where role <= %d %s order by ordinal", $role, $guest); $data = $db->query($sql); $ret = array(); - foreach ($data as $d) - { - if (!preg_match("/http/i", $d["href"])) - { + foreach ($data as $d) { + if (!preg_match("/http/i", $d["href"])) { $d["href"] = $serverurl . $d["href"]; $ret[] = $d; - } - else - { + } else { $ret[] = $d; } } diff --git a/lib/copy_this/www/lib/movie.php b/lib/copy_this/www/lib/movie.php index dddcab347..bfa43854a 100644 --- a/lib/copy_this/www/lib/movie.php +++ b/lib/copy_this/www/lib/movie.php @@ -84,14 +84,16 @@ class Movie { $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } $rsql = ''; - if ($moviename != "") - $rsql .= sprintf("and movieinfo.title like %s ", $db->escapeString("%" . $moviename . "%")); + if ($moviename != "") { + $rsql .= sprintf("and movieinfo.title like %s ", $db->escapeString("%" . $moviename . "%")); + } return $db->query(sprintf(" SELECT * FROM movieinfo where 1=1 %s ORDER BY createddate DESC" . $limit, $rsql)); } @@ -104,8 +106,9 @@ class Movie $db = new DB(); $rsql = ''; - if ($moviename != "") - $rsql .= sprintf("and movieinfo.title like %s ", $db->escapeString("%" . $moviename . "%")); + if ($moviename != "") { + $rsql .= sprintf("and movieinfo.title like %s ", $db->escapeString("%" . $moviename . "%")); + } $res = $db->queryOneRow(sprintf("select count(id) as num from movieinfo where 1=1 %s ", $rsql)); return $res["num"]; @@ -121,43 +124,41 @@ class Movie $browseby = $this->getBrowseBy(); $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { + if (count($cat) > 0 && $cat[0] != -1) { $catsrch = " ("; - foreach ($cat as $category) - { - if ($category != -1) - { + foreach ($cat as $category) { + if ($category != -1) { $categ = new Category(); - if ($categ->isParent($category)) - { + if ($categ->isParent($category)) { $children = $categ->getChildren($category); $chlist = "-99"; - foreach ($children as $child) - $chlist .= ", " . $child["id"]; + foreach ($children as $child) { + $chlist .= ", " . $child["id"]; + } - if ($chlist != "-99") - $catsrch .= " r.categoryid in (" . $chlist . ") or "; - } - else - { + if ($chlist != "-99") { + $catsrch .= " r.categoryid in (" . $chlist . ") or "; + } + } else { $catsrch .= sprintf(" r.categoryid = %d or ", $category); } } } $catsrch .= "1=2 )"; + } else { + $catsrch = " 1=1 "; } - else - $catsrch = " 1=1 "; - if ($maxage > 0) - $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; + if ($maxage > 0) { + $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } else { + $maxage = ""; + } $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + if (count($excludedcats) > 0) { + $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + } $sql = sprintf("select count(distinct r.imdbid) as num from releases r inner join movieinfo m on m.imdbid = r.imdbid and m.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s ", $browseby, $catsrch, $maxage, $exccatlist); $res = $db->queryOneRow($sql, true); @@ -173,48 +174,47 @@ class Movie $browseby = $this->getBrowseBy(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { + if (count($cat) > 0 && $cat[0] != -1) { $catsrch = " ("; - foreach ($cat as $category) - { - if ($category != -1) - { + foreach ($cat as $category) { + if ($category != -1) { $categ = new Category(); - if ($categ->isParent($category)) - { + if ($categ->isParent($category)) { $children = $categ->getChildren($category); $chlist = "-99"; - foreach ($children as $child) - $chlist .= ", " . $child["id"]; + foreach ($children as $child) { + $chlist .= ", " . $child["id"]; + } - if ($chlist != "-99") - $catsrch .= " r.categoryid in (" . $chlist . ") or "; - } - else - { + if ($chlist != "-99") { + $catsrch .= " r.categoryid in (" . $chlist . ") or "; + } + } else { $catsrch .= sprintf(" r.categoryid = %d or ", $category); } } } $catsrch .= "1=2 )"; + } else { + $catsrch = " 1=1 "; } - else - $catsrch = " 1=1 "; $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + if ($maxage > 0) { + $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + if (count($excludedcats) > 0) { + $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + } $order = $this->getMovieOrder($orderby); $sql = sprintf(" SELECT r.imdbid, max(r.postdate) as postdate, m.* from releases r inner join movieinfo m on m.imdbid = r.imdbid where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and m.title != '' and r.imdbid != 0000000 and %s %s %s %s group by r.imdbid order by %s %s" . $limit, $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1]); @@ -224,11 +224,11 @@ class Movie //get a copy of all the imdbs // $imdbds = ""; - foreach ($rows as $row) - $imdbds .= $row["imdbid"] . ", "; + foreach ($rows as $row) { + $imdbds .= $row["imdbid"] . ", "; + } - if (strlen($imdbds) > 0) - { + if (strlen($imdbds) > 0) { $imdbds = substr($imdbds, 0, -2); // @@ -546,7 +546,7 @@ class Movie } if (isset($movie['trailers']) && isset($movie['trailers']['youtube']) && sizeof($movie['trailers']['youtube']) > 0) { - foreach($movie['trailers']['youtube'] as $trailer) + foreach ($movie['trailers']['youtube'] as $trailer) { $ret['trailer'] = $trailer['source']; break; @@ -577,15 +577,16 @@ class Movie $ret = array(); $c = 0; - foreach ($movies['results'] as $movie) - { + foreach ($movies['results'] as $movie) { $c++; - if ($c >= $limit) - continue; + if ($c >= $limit) { + continue; + } $m = $this->fetchTmdbProperties($movie['id'], false); - if ($m !== false) - $ret[] = $m; + if ($m !== false) { + $ret[] = $m; + } } return $ret; } @@ -612,13 +613,10 @@ class Movie $buffer = Utility::getUrl(['url' => 'http://www.imdb.com/title/tt$imdbId/', 'method'=>'get', 'language' => $this->lookuplanguage]); // make sure we got some data - if ($buffer !== false && strlen($buffer)) - { + if ($buffer !== false && strlen($buffer)) { $ret = array(); - foreach ($imdb_regex as $field => $regex) - { - if (preg_match($regex, $buffer, $matches)) - { + foreach ($imdb_regex as $field => $regex) { + if (preg_match($regex, $buffer, $matches)) { $match = $matches[1]; $match = strip_tags(trim(rtrim($match))); $ret[$field] = $match; @@ -627,10 +625,8 @@ class Movie } } - foreach ($imdb_regex_multi as $field => $regex) - { - if (preg_match_all($regex, $buffer, $matches)) - { + foreach ($imdb_regex_multi as $field => $regex) { + if (preg_match_all($regex, $buffer, $matches)) { $match = $matches[1]; $match = array_map("trim", $match); $ret[$field] = $match; @@ -640,20 +636,16 @@ class Movie //directors - if (preg_match('/(.*?)<\/div>/is', $buffer, $hit)) - { - if (preg_match_all('/(.*?)<\/span>/is', $hit[1], $results, PREG_PATTERN_ORDER)) - { + if (preg_match('/(.*?)<\/div>/is', $buffer, $hit)) { + if (preg_match_all('/(.*?)<\/span>/is', $hit[1], $results, PREG_PATTERN_ORDER)) { $ret['director'] = $results[1]; } } //actors - if (preg_match('/(.*?)<\/div>/is', $buffer, $hit)) - { - if (preg_match_all('/(.*?)<\/span>/is', $hit[1], $results, PREG_PATTERN_ORDER)) - { + if (preg_match('/(.*?)<\/div>/is', $buffer, $hit)) { + if (preg_match_all('/(.*?)<\/span>/is', $hit[1], $results, PREG_PATTERN_ORDER)) { $ret['actors'] = $results[1]; } } @@ -702,10 +694,10 @@ class Movie if ($moviename !== false) { if ($this->echooutput) - echo 'MovProc : '.$moviename.' ['.$arr['searchname'].']'."\n"; + echo 'MovProc : ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n"; //$buffer = getUrl("https://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=".urlencode($moviename.' site:imdb.com')); - $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q='.urlencode($moviename.' site:imdb.com')]); + $buffer = Utility::getUrl(['url' => 'http://www.bing.com/search?&q=' . urlencode($moviename . ' site:imdb.com')]); // make sure we got some data if ($buffer !== false && strlen($buffer)) diff --git a/lib/copy_this/www/lib/music.php b/lib/copy_this/www/lib/music.php index bc27564da..b7ce25d58 100644 --- a/lib/copy_this/www/lib/music.php +++ b/lib/copy_this/www/lib/music.php @@ -54,10 +54,11 @@ class Music { $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } return $db->query(" SELECT * FROM musicinfo ORDER BY createddate DESC" . $limit); } @@ -82,26 +83,22 @@ class Music $browseby = $this->getBrowseBy(); $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { + if (count($cat) > 0 && $cat[0] != -1) { $catsrch = " ("; - foreach ($cat as $category) - { - if ($category != -1) - { + foreach ($cat as $category) { + if ($category != -1) { $categ = new Category(); - if ($categ->isParent($category)) - { + if ($categ->isParent($category)) { $children = $categ->getChildren($category); $chlist = "-99"; - foreach ($children as $child) - $chlist .= ", " . $child["id"]; + foreach ($children as $child) { + $chlist .= ", " . $child["id"]; + } - if ($chlist != "-99") - $catsrch .= " r.categoryid in (" . $chlist . ") or "; - } - else - { + if ($chlist != "-99") { + $catsrch .= " r.categoryid in (" . $chlist . ") or "; + } + } else { $catsrch .= sprintf(" r.categoryid = %d or ", $category); } } @@ -109,14 +106,16 @@ class Music $catsrch .= "1=2 )"; } - if ($maxage > 0) - $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; + if ($maxage > 0) { + $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } else { + $maxage = ""; + } $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + if (count($excludedcats) > 0) { + $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + } $sql = sprintf("select count(r.id) as num from releases r inner join musicinfo m on m.id = r.musicinfoid and m.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist); $res = $db->queryOneRow($sql, true); @@ -132,32 +131,29 @@ class Music $browseby = $this->getBrowseBy(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT " . $start . "," . $num; + if ($start === false) { + $limit = ""; + } else { + $limit = " LIMIT " . $start . "," . $num; + } $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { + if (count($cat) > 0 && $cat[0] != -1) { $catsrch = " ("; - foreach ($cat as $category) - { - if ($category != -1) - { + foreach ($cat as $category) { + if ($category != -1) { $categ = new Category(); - if ($categ->isParent($category)) - { + if ($categ->isParent($category)) { $children = $categ->getChildren($category); $chlist = "-99"; - foreach ($children as $child) - $chlist .= ", " . $child["id"]; + foreach ($children as $child) { + $chlist .= ", " . $child["id"]; + } - if ($chlist != "-99") - $catsrch .= " r.categoryid in (" . $chlist . ") or "; - } - else - { + if ($chlist != "-99") { + $catsrch .= " r.categoryid in (" . $chlist . ") or "; + } + } else { $catsrch .= sprintf(" r.categoryid = %d or ", $category); } } @@ -166,12 +162,14 @@ class Music } $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + if ($maxage > 0) { + $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); + } $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + if (count($excludedcats) > 0) { + $exccatlist = " and r.categoryid not in (" . implode(",", $excludedcats) . ")"; + } $order = $this->getMusicOrder($orderby); // query modified to join to musicinfo after limiting releases as performance issue prevented sane sql. @@ -239,15 +237,14 @@ class Music $browseby = ' '; $browsebyArr = $this->getBrowseByOptions(); - foreach ($browsebyArr as $bbk=>$bbv) - { - if (isset($_REQUEST[$bbk]) && !empty($_REQUEST[$bbk])) - { + foreach ($browsebyArr as $bbk=>$bbv) { + if (isset($_REQUEST[$bbk]) && !empty($_REQUEST[$bbk])) { $bbs = stripslashes($_REQUEST[$bbk]); - if (preg_match('/id/i', $bbv)) - $browseby .= "m.{$bbv} = $bbs AND "; - else - $browseby .= "m.$bbv LIKE(" . $db->escapeString('%' . $bbs . '%') . ") AND "; + if (preg_match('/id/i', $bbv)) { + $browseby .= "m.{$bbv} = $bbs AND "; + } else { + $browseby .= "m.$bbv LIKE(" . $db->escapeString('%' . $bbs . '%') . ") AND "; + } } } return $browseby; @@ -275,8 +272,9 @@ class Music $mus = array(); $amaz = $this->fetchAmazonProperties($artist . " " . $album); - if (!$amaz) - return false; + if (!$amaz) { + return false; + } sleep(1); @@ -291,44 +289,50 @@ class Music // get album properties // $mus['coverurl'] = (string)$amaz->Items->Item->LargeImage->URL; - if ($mus['coverurl'] != "") - $mus['cover'] = 1; - else - $mus['cover'] = 0; + if ($mus['coverurl'] != "") { + $mus['cover'] = 1; + } else { + $mus['cover'] = 0; + } $mus['title'] = (string)$amaz->Items->Item->ItemAttributes->Title; - if (empty($mus['title'])) - $mus['title'] = $album; + if (empty($mus['title'])) { + $mus['title'] = $album; + } $mus['asin'] = (string)$amaz->Items->Item->ASIN; $mus['url'] = (string)$amaz->Items->Item->DetailPageURL; $mus['salesrank'] = (string)$amaz->Items->Item->SalesRank; - if ($mus['salesrank'] == "") - $mus['salesrank'] = 'null'; + if ($mus['salesrank'] == "") { + $mus['salesrank'] = 'null'; + } $mus['artist'] = (string)$amaz->Items->Item->ItemAttributes->Artist; - if (empty($mus['artist'])) - $mus['artist'] = $artist; + if (empty($mus['artist'])) { + $mus['artist'] = $artist; + } $mus['publisher'] = (string)$amaz->Items->Item->ItemAttributes->Publisher; $mus['releasedate'] = $db->escapeString((string)$amaz->Items->Item->ItemAttributes->ReleaseDate); - if ($mus['releasedate'] == "''") - $mus['releasedate'] = 'null'; + if ($mus['releasedate'] == "''") { + $mus['releasedate'] = 'null'; + } $mus['review'] = ""; - if (isset($amaz->Items->Item->EditorialReviews)) - $mus['review'] = trim(strip_tags((string)$amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + if (isset($amaz->Items->Item->EditorialReviews)) { + $mus['review'] = trim(strip_tags((string)$amaz->Items->Item->EditorialReviews->EditorialReview->Content)); + } $mus['year'] = $year; - if ($mus['year'] == "") - $mus['year'] = ($mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y")); + if ($mus['year'] == "") { + $mus['year'] = ($mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y")); + } $mus['tracks'] = ""; - if (isset($amaz->Items->Item->Tracks)) - { + if (isset($amaz->Items->Item->Tracks)) { $tmpTracks = (array)$amaz->Items->Item->Tracks->Disc; $tracks = $tmpTracks['Track']; $mus['tracks'] = (is_array($tracks) && !empty($tracks)) ? implode('|', $tracks) : ''; @@ -343,40 +347,38 @@ class Music //echo("Matched: Album Percentage: $albumpercent%"); //If the artist is Various Artists, assume artist is 100% - if (preg_match('/various/i', $artist)) - $artistpercent = '100'; + if (preg_match('/various/i', $artist)) { + $artistpercent = '100'; + } //If the Artist is less than 80% album must be 100% - if ($artistpercent < '80') - { - if ($albumpercent != '100') - return false; + if ($artistpercent < '80') { + if ($albumpercent != '100') { + return false; + } } //If the album is ever under 30%, it's probably not a match. - if ($albumpercent < '30') - return false; + if ($albumpercent < '30') { + return false; + } //This is the end of the recheck code. Comment out to this point to show all info. $genreKey = -1; $genreName = ''; - if (isset($amaz->Items->Item->BrowseNodes)) - { + if (isset($amaz->Items->Item->BrowseNodes)) { //had issues getting this out of the browsenodes obj //workaround is to get the xml and load that into its own obj $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml(); $amazGenresObj = simplexml_load_string($amazGenresXml); $amazGenres = $amazGenresObj->xpath("//BrowseNodeId"); - foreach ($amazGenres as $amazGenre) - { + foreach ($amazGenres as $amazGenre) { $currNode = trim($amazGenre[0]); - if (empty($genreName)) - { + if (empty($genreName)) { $genreMatch = $this->matchBrowseNode($currNode); - if ($genreMatch !== false) - { + if ($genreMatch !== false) { $genreName = $genreMatch; break; } @@ -406,22 +408,16 @@ class Music public function fetchAmazonProperties($title) { $obj = new AmazonProductAPI($this->pubkey, $this->privkey, $this->asstag); - try - { + try { $result = $obj->searchProducts($title, AmazonProductAPI::MP3, "TITLE"); - } - catch (Exception $e) - { + } catch (Exception $e) { //if first search failed try the mp3downloads section - try - { + try { // sleep for 1 second sleep(1); $result = $obj->searchProducts($title, AmazonProductAPI::MUSIC, "TITLE"); - } - catch (Exception $e2) - { + } catch (Exception $e2) { $result = false; } } @@ -439,40 +435,36 @@ class Music $numlookedup = 0; $res = $db->queryDirect(sprintf("SELECT searchname, id from releases where musicinfoid IS NULL and categoryid in ( select id from category where parentid = %d ) ORDER BY postdate DESC LIMIT 1000", Category::CAT_PARENT_MUSIC)); - if ($db->getNumRows($res) > 0) - { - if ($this->echooutput) - echo "MusicPr : Processing " . $db->getNumRows($res) . " audio releases\n"; + if ($db->getNumRows($res) > 0) { + if ($this->echooutput) { + echo "MusicPr : Processing " . $db->getNumRows($res) . " audio releases\n"; + } - while ($arr = $db->getAssocArray($res)) - { - if ($numlookedup > Music::NUMTOPROCESSPERTIME) - return; + while ($arr = $db->getAssocArray($res)) { + if ($numlookedup > Music::NUMTOPROCESSPERTIME) { + return; + } $albumId = -2; $album = $this->parseArtist($arr['searchname']); - if ($album !== false) - { - if ($this->echooutput) - echo 'MusicPr : Looking up: ' . $album["artist"] . ' - ' . $album["album"] . "\n"; + if ($album !== false) { + if ($this->echooutput) { + echo 'MusicPr : Looking up: ' . $album["artist"] . ' - ' . $album["album"] . "\n"; + } //check for existing music entry $albumCheck = $this->getMusicInfoByName($album["artist"], $album["album"]); - if ($albumCheck === false) - { + if ($albumCheck === false) { // // get from amazon // $numlookedup++; $ret = $this->updateMusicInfo($album["artist"], $album["album"], $album['year']); - if ($ret !== false) - { + if ($ret !== false) { $albumId = $ret; } - } - else - { + } else { $albumId = $albumCheck["id"]; } } @@ -511,22 +503,19 @@ class Music $name = explode("-", $newName); $name = array_map("trim", $name); - if (is_array($name) && sizeof($name) > 1) - { + if (is_array($name) && sizeof($name) > 1) { $albumi = 1; - if ((strlen($name[0]) <= 2 || strlen($name[1]) <= 2) && !preg_match('/Various Artists/i', $name[0])) - { + if ((strlen($name[0]) <= 2 || strlen($name[1]) <= 2) && !preg_match('/Various Artists/i', $name[0])) { $name[0] = $name[0] . '-' . $name[1]; $albumi = 2; - } - elseif (strlen($name[1]) <= 2 && preg_match('/Various Artists/i', $name[0]) && sizeof($name) > 2) - { + } elseif (strlen($name[1]) <= 2 && preg_match('/Various Artists/i', $name[0]) && sizeof($name) > 2) { $name[2] = $name[1] . '-' . $name[2]; $albumi = 2; } - if (!isset($name[$albumi])) - return false; + if (!isset($name[$albumi])) { + return false; + } if (preg_match('/^the /i', $name[0])) { $name[0] = preg_replace('/^the /i', '', $name[0]) . ', The'; @@ -539,10 +528,8 @@ class Music } //make sure we've actually matched an album name - if (isset($result['album'])) - { - if (preg_match('/^(nmrVBR|VBR|WEB|SAT|20\d{2}|19\d{2}|CDM|EP)$/i', $result['album'])) - { + if (isset($result['album'])) { + if (preg_match('/^(nmrVBR|VBR|WEB|SAT|20\d{2}|19\d{2}|CDM|EP)$/i', $result['album'])) { $result['album'] = ''; } } @@ -564,25 +551,24 @@ class Music $res = $db->query("SELECT r.searchname, ref.releaseid, ref.mediainfo FROM releaseextrafull ref INNER JOIN releases r ON r.id = ref.releaseid WHERE r.musicinfoid = -2"); $rescount = sizeof($res); - if ($rescount > 0) - { - if ($this->echooutput) - echo "MusicPr : Processing " . $rescount . " audio releases via mediainfo\n"; + if ($rescount > 0) { + if ($this->echooutput) { + echo "MusicPr : Processing " . $rescount . " audio releases via mediainfo\n"; + } //load genres $gen = new Genres(); $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE); $genreassoc = array(); - foreach ($defaultGenres as $dg) - $genreassoc[$dg['id']] = strtolower($dg['title']); + foreach ($defaultGenres as $dg) { + $genreassoc[$dg['id']] = strtolower($dg['title']); + } - foreach ($res as $rel) - { + foreach ($res as $rel) { $albumId = -3; $mi = null; $mi = @simplexml_load_string($rel["mediainfo"]); - if ($mi != null) - { + if ($mi != null) { $artist = (string)$mi->File->track[0]->Performer; $album = (string)$mi->File->track[0]->Album; $year = (string)$mi->File->track[0]->Recorded_date; @@ -590,18 +576,16 @@ class Music $publisher = (string)$mi->File->track[0]->Publisher; $albumCheck = $this->getMusicInfoByName($artist, $album); - if ($albumCheck === false) - { + if ($albumCheck === false) { // // insert new musicinfo // $genreKey = -1; - if ($genre != "") - $albumId = $this->addUpdateMusicInfo($album, "", "", "null", $artist, + if ($genre != "") { + $albumId = $this->addUpdateMusicInfo($album, "", "", "null", $artist, $publisher, "null", "", $year, $genreKey, "", 0); - } - else - { + } + } else { $albumId = $albumCheck["id"]; } } @@ -624,12 +608,12 @@ class Music $db = new DB(); if (strlen($year) > 4) { - if (preg_match("/\d{4}/", $year, $matches)) - $year = $db->escapeString($matches[0]); - else - $year = "null"; - } - else { + if (preg_match("/\d{4}/", $year, $matches)) { + $year = $db->escapeString($matches[0]); + } else { + $year = "null"; + } + } else { $year = $db->escapeString($year); } @@ -659,8 +643,7 @@ class Music $str = ''; //music nodes above mp3 download nodes - switch ($nodeId) - { + switch ($nodeId) { case '163420': $str = 'Music Video & Concerts'; break; diff --git a/lib/copy_this/www/lib/nfo.php b/lib/copy_this/www/lib/nfo.php index f43226f46..9b92c1506 100644 --- a/lib/copy_this/www/lib/nfo.php +++ b/lib/copy_this/www/lib/nfo.php @@ -7,10 +7,14 @@ require_once(WWW_DIR . "/lib/nzb.php"); require_once(WWW_DIR . "/lib/nzbinfo.php"); // Silent Error Handler (used to shut up noisy XML exceptions) -function nfoHandleError($errno, $errstr, $errfile, $errline, array $errcontext) { - if (0 === error_reporting()) - return false; - if (!defined('E_STRICT'))define('E_STRICT', 2048); +function nfoHandleError($errno, $errstr, $errfile, $errline, array $errcontext) +{ + if (0 === error_reporting()) { + return false; + } + if (!defined('E_STRICT')) { + define('E_STRICT', 2048); + } switch ($errno) { case E_WARNING: case E_NOTICE: @@ -63,17 +67,17 @@ class Nfo /** * Default constructor. */ - function Nfo($verbose=false, $use_obfuscated=true, $use_fuzzy=false) + function Nfo($verbose = false, $use_obfuscated = true, $use_fuzzy = false) { - $this->use_fuzzy=$use_fuzzy; - $this->use_obfuscated=$use_obfuscated; - $this->verbose=$verbose; + $this->use_fuzzy = $use_fuzzy; + $this->use_obfuscated = $use_obfuscated; + $this->verbose = $verbose; } /** * @param nzbInfo $nzbInfo */ - private function nfo_scan(&$nzbInfo){ + private function nfo_scan(&$nzbInfo) { // // Phase 1, iterate over nzb file for a relative // match on a possible nfo file @@ -85,20 +89,23 @@ class Nfo $nfo_idx = array(); // Search for all entries that have a single segment - if (empty($nzbInfo->segmentfiles)) - // Nothing to Return + if (empty($nzbInfo->segmentfiles)) { + // Nothing to Return return array(); + } // Fetch Meta Information - if (isset($nzbInfo->metadata['name'])) - $name = $nzbInfo->metadata['name']; - else - $name = ""; + if (isset($nzbInfo->metadata['name'])) { + $name = $nzbInfo->metadata['name']; + } else { + $name = ""; + } $unordered_list = array(); foreach ($nzbInfo->segmentfiles as $segment) { - if ($segment['filesize'] > Nfo::NFO_MAX_FILESIZE) - continue; + if ($segment['filesize'] > Nfo::NFO_MAX_FILESIZE) { + continue; + } $unordered_list[] = array( "name" => $name, @@ -120,22 +127,28 @@ class Nfo // foreach ($unordered_list as $idx => $n) { if (preg_match("/\.(nfo)([^a-z0-9]+|$)/i", $n["subject"])) { - if ($this->verbose) echo "[nfo] "; + if ($this->verbose) { + echo "[nfo] "; + } $nfo_idx[] = $n; } } // Handle Releases with Obfuscation // Releases titled: f4ca0f95896da1d41254bf49791a86a2 - if ($this->use_obfuscated) - foreach ($unordered_list as $idx => $n) { + if ($this->use_obfuscated) { + foreach ($unordered_list as $idx => $n) { if (preg_match("/\.(sfv)([^a-z0-9]+|$)/i", $n["subject"])) continue; - if (preg_match("/\.(nzb)([^a-z0-9]+|$)/i", $n["subject"])) - continue; + } + if (preg_match("/\.(nzb)([^a-z0-9]+|$)/i", $n["subject"])) { + continue; + } if (preg_match("/\.[0-9]+([^a-z0-9\.-]+|$)/i", $n["subject"])) { - if ($this->verbose) echo "[obfs] "; + if ($this->verbose) { + echo "[obfs] "; + } $nfo_idx[] = $n; } } @@ -143,10 +156,11 @@ class Nfo // Fuzzy Parsing sees if it can identify other possible nfo's however // they are appended to the end of the list obvious nfo's are always // processed first - if ($this->use_fuzzy) - foreach ($unordered_list as $idx => $n) { + if ($this->use_fuzzy) { + foreach ($unordered_list as $idx => $n) { if (preg_match("/\.(txt|diz)([^a-z0-9]+|$)/i", $n["subject"])) { if ($this->verbose) echo "[fuzz] "; + } $nfo_idx[] = $n; } } @@ -156,7 +170,8 @@ class Nfo return $nfo_idx; } - private function is_binary(&$raw) { + private function is_binary(&$raw) + { // Returns true if data passed in is binary, otherwise // returns false, $has_binary = ( @@ -165,13 +180,11 @@ class Nfo or substr_count($raw, "\x00") > 0 ); - if ($has_binary) - { + if ($has_binary) { // Before we rule it completely out, see if we can detect it // as utf-16 $result = iconv($in_charset = 'UTF-16LE', $out_charset = 'UTF-8', $raw); - if (false !== $result) - { + if (false !== $result) { // not binary, we decoded it // we're dealing with a utf-16 type file... // store it as utf-8 @@ -184,13 +197,15 @@ class Nfo return ($has_binary) ? true : false; } - private function is_par2(&$raw) { + private function is_par2(&$raw) + { // Returns true if data passed in is binary, otherwise // returns false, return (substr($raw, 4) == "PAR2"); } - private function is_sfv(&$raw) { + private function is_sfv(&$raw) + { // scan a content and return true if it is detected to be // an sfv file, otherwise return false @@ -210,18 +225,21 @@ class Nfo // on every line then we are dealing with an sfv file foreach (preg_split("/((\r?\n)|(\r\n?))/", $raw) as $line) { $matches = false; - foreach ($sfv_regex as $regex) - if (preg_match($regex, $line)) { + foreach ($sfv_regex as $regex) { + if (preg_match($regex, $line)) { $matches = true; + } break; } - if (!$matches) - return false; + if (!$matches) { + return false; + } } return true; } - private function store_blob($nfometa, $blobhash, $removed) { + private function store_blob($nfometa, $blobhash, $removed) + { // This takes a array of blobs with their index id being // the release id; In the event we fetch the data and deem // it no good, we need to add it to the skipped array which @@ -235,12 +253,16 @@ class Nfo $uid, $db->escapeString($blob)); $id = $db->queryInsert($query); if (!$id) { - if ($this->verbose) echo "!"; + if ($this->verbose) { + echo "!"; + } } else { $query = sprintf("UPDATE releases SET releasenfoid = %d WHERE id = %d LIMIT 1", $id, $uid); $res = $db->queryExec($query); - if ($this->verbose) echo "s"; + if ($this->verbose) { + echo "s"; + } } } @@ -249,14 +271,19 @@ class Nfo foreach ($removed as $uid) { $res = $this->setNfoMissing($uid); if ($res <= 0) { - if ($this->verbose) echo "!"; + if ($this->verbose) { + echo "!"; + } } else { - if ($this->verbose) echo "s"; + if ($this->verbose) { + echo "s"; + } } } } - private function parse_blobs(&$nfometa, &$nfoblob) { + private function parse_blobs(&$nfometa, &$nfoblob) + { // Parses an array of array of blobs and determines the most // ideal nfo from them. // @@ -315,34 +342,46 @@ class Nfo // no blob or the data failed to fetch, we can rule // this entry out right away if (!array_key_exists($uid, $nfoblob)) { - if ($this->verbose) echo '-'; + if ($this->verbose) { + echo '-'; + } continue; } if (!array_key_exists($idx, $nfoblob[$uid])) { - if ($this->verbose) echo '-'; + if ($this->verbose) { + echo '-'; + } continue; } if ($nfoblob[(string)$uid][$idx] === Null) { - if ($this->verbose) echo '-'; + if ($this->verbose) { + echo '-'; + } continue; } // Eliminate detected xml (usually nzb) files if (preg_match('/xmlns[^=]*="[^"]*"/i', $nfoblob[$uid][$idx]) || preg_match("/(\<\?xml[\d\D]*\?\>)/i", $nfoblob[$uid][$idx])) { - if ($this->verbose) echo '-'; + if ($this->verbose) { + echo '-'; + } continue; } // We do not want to pick up sfv files if ($this->is_sfv($nfoblob[$uid][$idx])) { - if ($this->verbose) echo '-'; + if ($this->verbose) { + echo '-'; + } continue; } // We do not want to pick up par2 files if ($this->is_par2($nfoblob[$uid][$idx])) { - if ($this->verbose) echo '-'; + if ($this->verbose) { + echo '-'; + } continue; } // Ideally if code reaches this far @@ -356,7 +395,9 @@ class Nfo // An ideal match was found $parsed_blob[(string)$uid] = $nfoblob[$uid][$ideal]; $parsed_meta[(string)$uid] = $nfometa[$uid][$ideal]; - if ($this->verbose) echo '+'; + if ($this->verbose) { + echo '+'; + } } else { // No valid data unset($parsed_blob[(string)$uid]); @@ -374,7 +415,8 @@ class Nfo return count($nfoblob); } - private function _nfo_grab($nfometa, &$blobhash) { + private function _nfo_grab($nfometa, &$blobhash) + { // nfometa should be an array() of segments from nzb file // it will then populate the blobhash which uses the segments // as hash entries for the blob data. @@ -421,18 +463,24 @@ class Nfo $fetched = false; foreach ($match["groups"] as $group) { // Don not try other groups if we already got it - if ($fetched)break; + if ($fetched) { + break; + } // Select the group and then attempt to fetch the article $blob = $nntp->getMessages($group, $match["segment"], false); if ($blob === false) { - if ($this->verbose) echo '*'; + if ($this->verbose) { + echo '*'; + } continue; } // Mark that we fetched it to prevent fetching more // of the same thing $fetched = true; - if ($this->verbose) echo '.'; + if ($this->verbose) { + echo '.'; + } // Update blob with decrypted version and store if ($this->is_binary($blob)) { @@ -443,15 +491,17 @@ class Nfo // Read-able ascii at this point... store it $blobhash[$uid][$idx] = $blob; } - if (!$fetched) - // handle empty/failed segments + if (!$fetched) { + // handle empty/failed segments $blobhash[$uid][$idx] = Null; + } } } $nntp->doQuit(); } - private function nfo_grab($nfometa, &$blobhash) { + private function nfo_grab($nfometa, &$blobhash) + { // It is possible for connection to drop while attempting // to fetch nfo content, to accomodate for the exceptions // thrown during this time we wrap the real nfo_grab() @@ -465,8 +515,10 @@ class Nfo break; } catch (Exception $e) { // Connection lost - if ($this->verbose) echo sprintf("\n%s Connection lost to usenet (%d retries left).\n", + if ($this->verbose) { + echo sprintf("\n%s Connection lost to usenet (%d retries left).\n", 'NfoProc', $retries); + } // Decrement retry count $retries--; // Reset blobhash @@ -477,9 +529,9 @@ class Nfo // Restore handler as any future errors really are... code errors :) restore_error_handler(); - if($retries>0){ + if ($retries > 0) { foreach ($_blobhash as $k => $v) - $blobhash[(string)$k]=$v; + $blobhash[(string)$k] = $v; return true; } return false; @@ -490,7 +542,7 @@ class Nfo * @param integer $total * @param integer $limit */ - private function scan_releases(&$processed, &$total, $limit=Null){ + private function scan_releases(&$processed, &$total, $limit = Null) { // Scan all nzb files whos releases match against data // that has no nfo files associated with it. // @@ -527,57 +579,57 @@ class Nfo $nzbInfo = new NzbInfo(); if (!$nzbInfo->loadFromFile($nzbfile)) { - if($this->verbose) echo sprintf("%s Unable to parse NZB File: %d/%s ...\n", + if ($this->verbose) echo sprintf("%s Unable to parse NZB File: %d/%s ...\n", 'NfoProc', intval($r["id"]), $r["name"]); $this->setNfoMissing($r["id"]); continue; } - $total+=1; + $total += 1; $filename = basename($nzbfile); - if($this->verbose) { + if ($this->verbose) { echo sprintf("NfoProc : Scanning %s - ", $r["name"]); } $matches = $this->nfo_scan($nzbInfo); unset($nzbInfo); - if(is_array($matches)) { - if(!count($matches)) { - if($this->verbose) { + if (is_array($matches)) { + if (!count($matches)) { + if ($this->verbose) { echo "nfo missing.\n"; } $this->setNfoMissing($r["id"]); continue; } } else { - if($this->verbose) { + if ($this->verbose) { echo "corrupt nzb.\n"; } $this->setNfoMissing($r["id"]); continue; } - if($this->verbose) { - echo count($matches)." possible nfo(s).\n"; + if ($this->verbose) { + echo count($matches) . " possible nfo(s).\n"; } $processed++; // Hash Matches by Release id $nfometa[(string)$r["id"]] = $matches; - if(!($processed%$batch)) { + if (!($processed % $batch)) { $nfoblob = array(); - if($this->verbose) { + if ($this->verbose) { echo "NfoProc : Retrieval ..."; } - if($this->nfo_grab($nfometa, $nfoblob)) { + if ($this->nfo_grab($nfometa, $nfoblob)) { $before = array_keys($nfoblob); $this->parse_blobs($nfometa, $nfoblob); $after = array_keys($nfoblob); $removed = array_diff($before, $after); $this->store_blob($nfometa, $nfoblob, $removed); } - if($this->verbose) { + if ($this->verbose) { echo "\n"; } @@ -585,19 +637,19 @@ class Nfo $nfometa = array(); } } - if(($processed%$batch)) { + if (($processed % $batch)) { $nfoblob = array(); - if($this->verbose) { + if ($this->verbose) { echo "NfoProc : Retrieval ..."; } - if($this->nfo_grab($nfometa, $nfoblob)) { + if ($this->nfo_grab($nfometa, $nfoblob)) { $before = array_keys($nfoblob); $this->parse_blobs($nfometa, $nfoblob); $after = array_keys($nfoblob); $removed = array_diff($before, $after); $this->store_blob($nfometa, $nfoblob, $removed); } - if($this->verbose) { + if ($this->verbose) { echo "\n"; } } @@ -637,8 +689,7 @@ class Nfo "INNER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.id = r.releasenfoid " . "WHERE rn.nfo IS NOT NULL AND r.id = %d LIMIT 1"; $res = $db->queryOneRow(sprintf($mnfo, $relid)); - if ($res && isset($res['nfo'])) - { + if ($res && isset($res['nfo'])) { $nfoout = $res['nfo']; return true; } @@ -653,7 +704,9 @@ class Nfo $processed = 0; $total = 0; $this->scan_releases($processed, $total, $batch); - if ($this->verbose) echo sprintf("NfoProc : Complete %d NFOs detected from %d scanned NZB files.\n", $processed, $total); + if ($this->verbose) { + echo sprintf("NfoProc : Complete %d NFOs detected from %d scanned NZB files.\n", $processed, $total); + } return $total; } diff --git a/lib/copy_this/www/lib/nntp.php b/lib/copy_this/www/lib/nntp.php index 5cc36d9bd..bcc8bbd36 100644 --- a/lib/copy_this/www/lib/nntp.php +++ b/lib/copy_this/www/lib/nntp.php @@ -1061,26 +1061,28 @@ class NNTP extends Net_NNTP_Client */ // yEnc 1.3 draft doesn't allow line lengths of more than 254 bytes. - if ($linelen > 254) - $linelen = 254; + if ($linelen > 254) { + $linelen = 254; + } - if ($linelen < 1) - return false; + if ($linelen < 1) { + return false; + } $encoded = ""; // Encode each character of the message one at a time. - for ($i = 0; $i < strlen($message); $i++) - { + for ($i = 0; $i < strlen($message); $i++) { $value = (ord($message{$i}) + 42) % 256; // Escape NULL, TAB, LF, CR, space, . and = characters. if ($value == 0 || $value == 9 || $value == 10 || $value == 13 || $value == 32 || $value == 46 || - $value == 61) - $encoded .= "=" . chr(($value + 64) % 256); - else - $encoded .= chr($value); + $value == 61) { + $encoded .= "=" . chr(($value + 64) % 256); + } else { + $encoded .= chr($value); + } } // Wrap the lines to $linelen characters @@ -1092,8 +1094,9 @@ class NNTP extends Net_NNTP_Client $encoded .= "\r\n=yend size=" . strlen($message); // Add a CRC32 checksum if desired. - if ($crc32 === true) - $encoded .= " crc32=" . strtolower(sprintf("%04X", crc32($message))); + if ($crc32 === true) { + $encoded .= " crc32=" . strtolower(sprintf("%04X", crc32($message))); + } return $encoded . "\r\n"; } @@ -1109,8 +1112,9 @@ class NNTP extends Net_NNTP_Client $ret = ""; $input = trim(preg_replace("/\r\n/im", "", preg_replace("/(^=yend.*)/im", "", preg_replace("/(^=ypart.*\\r\\n)/im", "", preg_replace("/(^=ybegin.*\\r\\n)/im", "", $input[1], 1), 1), 1))); - for ($chr = 0; $chr < strlen($input); $chr++) - $ret .= ($input[$chr] != "=" ? chr(ord($input[$chr]) - 42) : chr((ord($input[++$chr]) - 64) - 42)); + for ($chr = 0; $chr < strlen($input); $chr++) { + $ret .= ($input[$chr] != "=" ? chr(ord($input[$chr]) - 42) : chr((ord($input[++$chr]) - 64) - 42)); + } return $ret; } diff --git a/lib/copy_this/www/lib/nzbinfo.php b/lib/copy_this/www/lib/nzbinfo.php index 85e2b9a9b..94309e83b 100644 --- a/lib/copy_this/www/lib/nzbinfo.php +++ b/lib/copy_this/www/lib/nzbinfo.php @@ -69,42 +69,42 @@ class nzbInfo return $this->isLoaded; } - /** - * @param string $loc - */ - public function loadFromFile($loc, $loadAllVars=false) - { - $this->source = $loc; - $this->loadAllVars = $loadAllVars; + /** + * @param string $loc + */ + public function loadFromFile($loc, $loadAllVars=false) + { + $this->source = $loc; + $this->loadAllVars = $loadAllVars; - if (file_exists($loc)) - { - if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) - { - switch (strtolower($ext[1])) - { - case 'gz': - $loc = 'compress.zlib://' . $loc; - break; - case 'zip': - $zip = new ZipArchive; - if ($zip->open($loc) === true && $zip->numFiles == 1) - return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); - else - $loc = 'zip://' . $loc; - break; - } - } + if (file_exists($loc)) + { + if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) + { + switch (strtolower($ext[1])) + { + case 'gz': + $loc = 'compress.zlib://' . $loc; + break; + case 'zip': + $zip = new ZipArchive; + if ($zip->open($loc) === true && $zip->numFiles == 1) + return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); + else + $loc = 'zip://' . $loc; + break; + } + } - libxml_use_internal_errors(true); - $xmlObj = @simplexml_load_file($loc); - if ($this->isValidNzb($xmlObj)) - $this->parseNzb($xmlObj); + libxml_use_internal_errors(true); + $xmlObj = @simplexml_load_file($loc); + if ($this->isValidNzb($xmlObj)) + $this->parseNzb($xmlObj); - unset($xmlObj); - } - return $this->isLoaded; - } + unset($xmlObj); + } + return $this->isLoaded; + } public function summarize() { @@ -122,23 +122,23 @@ class nzbInfo if (!empty($this->metadata)) { $out[] = ' -metadata:'; - foreach($this->metadata as $mk=>$mv) - $out[] = ' -'.$mk.': '.$mv; + foreach ($this->metadata as $mk=>$mv) + $out[] = ' -' . $mk . ': ' . $mv; } - $out[] = ' -sngl: '.sizeof($this->segmentfiles); + $out[] = ' -sngl: ' . sizeof($this->segmentfiles); - $out[] = ' -pstr: '.$this->poster; - $out[] = ' -grps: '.implode(', ', $this->groups); - $out[] = ' -size: '.round(($this->filesize / 1048576), 2).' MB in '.$this->filecount.' Files'; - $out[] = ' -'.$this->rarcount.' rars'; - $out[] = ' -'.$this->parcount.' pars'; - $out[] = ' -'.$this->sfvcount.' sfvs'; - $out[] = ' -'.$this->zipcount.' zips'; - $out[] = ' -'.$this->videocount.' videos'; - $out[] = ' -'.$this->audiocount.' audios'; - $out[] = ' -cmpltn: '.$this->completion.'% ('.$this->segmentactual.'/'.$this->segmenttotal.')'; - $out[] = ' -pstd: '.date("Y-m-d H:i:s", $this->postedlast); + $out[] = ' -pstr: ' . $this->poster; + $out[] = ' -grps: ' . implode(', ', $this->groups); + $out[] = ' -size: ' . round(($this->filesize / 1048576), 2) . ' MB in ' . $this->filecount . ' Files'; + $out[] = ' -' . $this->rarcount . ' rars'; + $out[] = ' -' . $this->parcount . ' pars'; + $out[] = ' -' . $this->sfvcount . ' sfvs'; + $out[] = ' -' . $this->zipcount . ' zips'; + $out[] = ' -' . $this->videocount . ' videos'; + $out[] = ' -' . $this->audiocount . ' audios'; + $out[] = ' -cmpltn: ' . $this->completion . '% (' . $this->segmentactual . '/' . $this->segmenttotal . ')'; + $out[] = ' -pstd: ' . date("Y-m-d H:i:s", $this->postedlast); $out[] = ''; $out[] = ''; @@ -147,21 +147,19 @@ class nzbInfo private function isValidNzb($xmlObj) { - if (!$xmlObj || strtolower($xmlObj->getName()) != 'nzb' || !isset($xmlObj->file)) - return false; + if (!$xmlObj || strtolower($xmlObj->getName()) != 'nzb' || !isset($xmlObj->file)) { + return false; + } return true; } private function parseNzb($xmlObj) - { + { //Metadata - if (isset($xmlObj->head->meta)) - { - foreach ($xmlObj->head->meta as $meta) - { - if (isset($meta->attributes()->type)) - { + if (isset($xmlObj->head->meta)) { + foreach ($xmlObj->head->meta as $meta) { + if (isset($meta->attributes()->type)) { $metaKey = (string)$meta->attributes()->type; $this->metadata[$metaKey] = (string)$meta; } @@ -170,11 +168,11 @@ class nzbInfo //NZB GID = first segment of first file $gid = (string)$xmlObj->file->segments->segment; - if (!empty($gid)) - $this->gid = md5($gid); + if (!empty($gid)) { + $this->gid = md5($gid); + } - foreach ($xmlObj->file as $file) - { + foreach ($xmlObj->file as $file) { $fileArr = array(); $fileArr['subject'] = (string)$file->attributes()->subject; $fileArr['poster'] = (string)$file->attributes()->poster; @@ -205,21 +203,21 @@ class nzbInfo //groups foreach ($file->groups->group as $group) { - $this->groups[] = (string) $group; - $fileArr['groups'][] = (string) $group; + $this->groups[] = (string)$group; + $fileArr['groups'][] = (string)$group; } //file segments - foreach($file->segments->segment as $segment) { - $bytes = (int) $segment->attributes()->bytes; - $number = (int) $segment->attributes()->number; + foreach ($file->segments->segment as $segment) { + $bytes = (int)$segment->attributes()->bytes; + $number = (int)$segment->attributes()->number; $this->filesize += $bytes; $this->segmentactual++; $fileArr['filesize'] += $bytes; $fileArr['segmentactual']++; - $fileArr['segments'][$number] = (string) $segment; + $fileArr['segments'][$number] = (string)$segment; $fileArr['segmentbytes'][$number] = $bytes; } @@ -227,19 +225,19 @@ class nzbInfo preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); $matchcnt = sizeof($matches[0]); $msgPart = $msgTotalParts = 0; - for ($i=0; $i<$matchcnt; $i++) + for ($i = 0; $i < $matchcnt; $i++) { //not (int)'d here because of the preg_replace later on $msgPart = $matches[1][$i]; $msgTotalParts = $matches[2][$i]; } - if((int)$msgPart > 0 && (int)$msgTotalParts > 0) + if ((int)$msgPart > 0 && (int)$msgTotalParts > 0) { - $this->segmenttotal += (int) $msgTotalParts; - $fileArr['segmenttotal'] = (int) $msgTotalParts; - $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); + $this->segmenttotal += (int)$msgTotalParts; + $fileArr['segmenttotal'] = (int)$msgTotalParts; + $fileArr['completion'] = number_format(($fileArr['segmentactual'] / $fileArr['segmenttotal']) * 100, 0); - $fileArr['subject'] = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $subject))); + $fileArr['subject'] = utf8_encode(trim(preg_replace('|\(' . $msgPart . '[\/]' . $msgTotalParts . '\)|i', '', $subject))); } //file counts @@ -334,27 +332,27 @@ class nzbInfo if (!empty($this->metadata)) { $nzb .= "\n"; - foreach($this->metadata as $mk=>$mv) - $out[] = ' '.$mv."\n"; + foreach ($this->metadata as $mk=>$mv) + $out[] = ' ' . $mv . "\n"; $nzb .= "\n"; } - foreach($this->nzb as $postFile) + foreach ($this->nzb as $postFile) { - $nzb .= "\n"; + $nzb .= "\n"; $nzb .= " \n"; - foreach($postFile['groups'] as $fileGroup) + foreach ($postFile['groups'] as $fileGroup) { - $nzb .= " ".$fileGroup."\n"; + $nzb .= " " . $fileGroup . "\n"; } $nzb .= " \n"; $nzb .= " \n"; - foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) + foreach ($postFile['segments'] as $fileSegmentNum=>$fileSegment) { - $nzb .= " ".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."\n"; + $nzb .= " " . htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8') . "\n"; } $nzb .= " \n\n"; } - $nzb .= "\n"; + $nzb .= "\n"; return $nzb; } diff --git a/lib/copy_this/www/lib/nzbvortex.php b/lib/copy_this/www/lib/nzbvortex.php index 83f81f86d..2a6c033d7 100644 --- a/lib/copy_this/www/lib/nzbvortex.php +++ b/lib/copy_this/www/lib/nzbvortex.php @@ -5,303 +5,303 @@ require_once sprintf('%s/lib/page.php', WWW_DIR); final class NZBVortex { - protected $nonce = null; - protected $session = null; + protected $nonce = null; + protected $session = null; - public function __construct() - { - if (is_null($this->session)) { - $this->getNonce(); - $this->login(); - } - } + public function __construct() + { + if (is_null($this->session)) { + $this->getNonce(); + $this->login(); + } + } - /** - * get text for state - * @param int $code - * @return string - */ - public function getState($code = 0) - { - $states = array( - 0 => 'Waiting', - 1 => 'Downloading', - 2 => 'Waiting for save', - 3 => 'Saving', - 4 => 'Saved', - 5 => 'Password request', - 6 => 'Queued for processing', - 7 => 'User wait for processing', - 8 => 'Checking', - 9 => 'Repairing', - 10 => 'Joining', - 11 => 'Wait for further processing', - 12 => 'Joining', - 13 => 'Wait for uncompress', - 14 => 'Uncompressing', - 15 => 'Wait for cleanup', - 16 => 'Cleaning up', - 17 => 'Cleaned up', - 18 => 'Moving to completed', - 19 => 'Move completed', - 20 => 'Done', - 21 => 'Uncompress failed', - 22 => 'Check failed, data corrupt', - 23 => 'Move failed', - 24 => 'Badly encoded download (uuencoded)' - ); + /** + * get text for state + * @param int $code + * @return string + */ + public function getState($code = 0) + { + $states = array( + 0 => 'Waiting', + 1 => 'Downloading', + 2 => 'Waiting for save', + 3 => 'Saving', + 4 => 'Saved', + 5 => 'Password request', + 6 => 'Queued for processing', + 7 => 'User wait for processing', + 8 => 'Checking', + 9 => 'Repairing', + 10 => 'Joining', + 11 => 'Wait for further processing', + 12 => 'Joining', + 13 => 'Wait for uncompress', + 14 => 'Uncompressing', + 15 => 'Wait for cleanup', + 16 => 'Cleaning up', + 17 => 'Cleaned up', + 18 => 'Moving to completed', + 19 => 'Move completed', + 20 => 'Done', + 21 => 'Uncompress failed', + 22 => 'Check failed, data corrupt', + 23 => 'Move failed', + 24 => 'Badly encoded download (uuencoded)' + ); - return (isset($states[$code])) ? - $states[$code] : -1; - } + return (isset($states[$code])) ? + $states[$code] : -1; + } - /** - * get overview of NZB's in queue - * @return array - */ - public function getOverview() - { - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('app/webUpdate'), $params); - foreach ($response['nzbs'] as &$nzb) { - $nzb['original_state'] = $nzb['state']; - $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); - } + /** + * get overview of NZB's in queue + * @return array + */ + public function getOverview() + { + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('app/webUpdate'), $params); + foreach ($response['nzbs'] as &$nzb) { + $nzb['original_state'] = $nzb['state']; + $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); + } - return $response; - } + return $response; + } - /** - * add NZB to queue - * @param string $nzb - * @return void - */ - public function addQueue($nzb = '') - { - if (!empty($nzb)) { - $page = new Page; - $user = new Users; + /** + * add NZB to queue + * @param string $nzb + * @return void + */ + public function addQueue($nzb = '') + { + if (!empty($nzb)) { + $page = new Page; + $user = new Users; - $host = $page->serverurl; - $data = $user->getById($user->currentUserId()); - $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); + $host = $page->serverurl; + $data = $user->getById($user->currentUserId()); + $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); - $params = array( - 'sessionid' => $this->session, - 'url' => $url - ); + $params = array( + 'sessionid' => $this->session, + 'url' => $url + ); - $response = $this->sendRequest('nzb/add', $params); - } - } + $response = $this->sendRequest('nzb/add', $params); + } + } - /** - * resume NZB - * @param int $id - * @return void - */ - public function resume($id = 0) - { - if ($id > 0) { - # /nzb/(id)/resume - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); - } - } + /** + * resume NZB + * @param int $id + * @return void + */ + public function resume($id = 0) + { + if ($id > 0) { + # /nzb/(id)/resume + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); + } + } - /** - * pause NZB - * @param int $id - * @return void - */ - public function pause($id = 0) - { - if ($id > 0) { - # /nzb/(id)/pause - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); - } - } + /** + * pause NZB + * @param int $id + * @return void + */ + public function pause($id = 0) + { + if ($id > 0) { + # /nzb/(id)/pause + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); + } + } - /** - * move NZB up in queue - * @param int $id - * @return void - */ - public function moveUp($id = 0) - { - if ($id > 0) { - # nzb/(nzbid)/moveup - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); - } - } + /** + * move NZB up in queue + * @param int $id + * @return void + */ + public function moveUp($id = 0) + { + if ($id > 0) { + # nzb/(nzbid)/moveup + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); + } + } - /** - * move NZB down in queue - * @param int $id - * @return void - */ - public function moveDown($id = 0) - { - if ($id > 0) { - # nzb/(nzbid)/movedown - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); - } - } + /** + * move NZB down in queue + * @param int $id + * @return void + */ + public function moveDown($id = 0) + { + if ($id > 0) { + # nzb/(nzbid)/movedown + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); + } + } - /** - * move NZB to bottom of queue - * @param int $id - * @return void - */ - public function moveBottom($id = 0) - { - if ($id > 0) { - # nzb/(nzbid)/movebottom - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); - } - } + /** + * move NZB to bottom of queue + * @param int $id + * @return void + */ + public function moveBottom($id = 0) + { + if ($id > 0) { + # nzb/(nzbid)/movebottom + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); + } + } - /** - * Remove a (๏ฌnished/un๏ฌnished) NZB from queue and delete files - * @param int $id - * @return void - */ - public function delete($id = 0) - { - if ($id > 0) { - # nzb/(nzbid)/movebottom - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); - } - } + /** + * Remove a (๏ฌnished/un๏ฌnished) NZB from queue and delete files + * @param int $id + * @return void + */ + public function delete($id = 0) + { + if ($id > 0) { + # nzb/(nzbid)/movebottom + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); + } + } - /** - * move NZB to top of queue - * @param int $id - * @return void - */ - public function moveTop($id = 0) - { - if ($id > 0) { - # nzb/(nzbid)/movebottom - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); - } - } + /** + * move NZB to top of queue + * @param int $id + * @return void + */ + public function moveTop($id = 0) + { + if ($id > 0) { + # nzb/(nzbid)/movebottom + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); + } + } - /** - * get filelist for nzb - * @param int $id - * @return array|bool - */ - public function getFilelist($id = 0) - { - if ($id > 0) { - # ๏ฌle/(nzbid) - $params = array('sessionid' => $this->session); - $response = $this->sendRequest(sprintf('file/%s', $id), $params); - return $response; - } + /** + * get filelist for nzb + * @param int $id + * @return array|bool + */ + public function getFilelist($id = 0) + { + if ($id > 0) { + # ๏ฌle/(nzbid) + $params = array('sessionid' => $this->session); + $response = $this->sendRequest(sprintf('file/%s', $id), $params); + return $response; + } - return false; - } + return false; + } - /** - * get /auth/nonce - * @return void - */ - protected function getNonce() - { - $response = $this->sendRequest('auth/nonce'); - $this->nonce = $response['authNonce']; - } + /** + * get /auth/nonce + * @return void + */ + protected function getNonce() + { + $response = $this->sendRequest('auth/nonce'); + $this->nonce = $response['authNonce']; + } - /** - * @return void - */ - protected function login() - { - $user = new Users(); - $data = $user->getById($user->currentUserId()); - $cnonce = generateUuid(); - $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); - $hash = base64_encode($hash); + /** + * @return void + */ + protected function login() + { + $user = new Users(); + $data = $user->getById($user->currentUserId()); + $cnonce = generateUuid(); + $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); + $hash = base64_encode($hash); - $params = array( - 'nonce' => $this->nonce, - 'cnonce' => $cnonce, - 'hash' => $hash - ); + $params = array( + 'nonce' => $this->nonce, + 'cnonce' => $cnonce, + 'hash' => $hash + ); - $response = $this->sendRequest('auth/login', $params); + $response = $this->sendRequest('auth/login', $params); - if ('successful' == $response['loginResult']) { - $this->session = $response['sessionID']; - } + if ('successful' == $response['loginResult']) { + $this->session = $response['sessionID']; + } - if ('failed' == $response['loginResult']) { } - } + if ('failed' == $response['loginResult']) { } + } - /** - * sendRequest() - * @param string $path - * @return array - */ - protected function sendRequest($path, $params = array()) - { - $user = new Users; - $data = $user->getById($user->currentUserId()); + /** + * sendRequest() + * @param string $path + * @return array + */ + protected function sendRequest($path, $params = array()) + { + $user = new Users; + $data = $user->getById($user->currentUserId()); - $url = sprintf('%s/api', $data['nzbvortex_server_url']); - $params = http_build_query($params); - $ch = curl_init(sprintf("%s/%s?%s", $url, $path, $params)); + $url = sprintf('%s/api', $data['nzbvortex_server_url']); + $params = http_build_query($params); + $ch = curl_init(sprintf("%s/%s?%s", $url, $path, $params)); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - #curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); - #curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888'); + #curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); + #curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888'); - $response = curl_exec($ch); - $response = json_decode($response, true); - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $error = curl_error($ch); + $response = curl_exec($ch); + $response = json_decode($response, true); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $error = curl_error($ch); - curl_close($ch); + curl_close($ch); - switch ($status) { - case 0: - throw new Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); - break; + switch ($status) { + case 0: + throw new Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); + break; - case 200: - return $response; - break; + case 200: + return $response; + break; - case 403: - throw new Exception('Unable to login. Is your API key correct?'); - break; + case 403: + throw new Exception('Unable to login. Is your API key correct?'); + break; - default: - throw new Exception(sprintf("%s (%s): %s", $path, $status, $response['result'])); - break; - } - } + default: + throw new Exception(sprintf("%s (%s): %s", $path, $status, $response['result'])); + break; + } + } } \ No newline at end of file diff --git a/lib/copy_this/www/lib/page.php b/lib/copy_this/www/lib/page.php index 83bbe272d..6bcab359b 100644 --- a/lib/copy_this/www/lib/page.php +++ b/lib/copy_this/www/lib/page.php @@ -19,8 +19,9 @@ class Page extends BasePage parent::BasePage(); $role = Users::ROLE_GUEST; - if ($this->userdata != null) - $role = $this->userdata["role"]; + if ($this->userdata != null) { + $role = $this->userdata["role"]; + } $content = new Contents(); $f = new Forum(); @@ -28,8 +29,9 @@ class Page extends BasePage $this->smarty->assign('menulist', $menu->get($role, $this->serverurl)); $this->smarty->assign('usefulcontentlist', $content->getForMenuByTypeAndRole(Contents::TYPEUSEFUL, $role)); $this->smarty->assign('articlecontentlist', $content->getForMenuByTypeAndRole(Contents::TYPEARTICLE, $role)); - if ($this->userdata != null) - $this->smarty->assign('recentforumpostslist', $f->getRecentPosts($this->site->showrecentforumposts)); + if ($this->userdata != null) { + $this->smarty->assign('recentforumpostslist', $f->getRecentPosts($this->site->showrecentforumposts)); + } $this->smarty->assign('main_menu', $this->smarty->fetch('mainmenu.tpl')); $this->smarty->assign('useful_menu', $this->smarty->fetch('usefullinksmenu.tpl')); @@ -37,19 +39,22 @@ class Page extends BasePage $this->smarty->assign('recentposts_menu', $this->smarty->fetch('recentforumposts.tpl')); $category = new Category(); - if ($this->userdata != null) - $parentcatlist = $category->getForMenu($this->userdata["categoryexclusions"]); - else - $parentcatlist = $category->getForMenu(); + if ($this->userdata != null) { + $parentcatlist = $category->getForMenu($this->userdata["categoryexclusions"]); + } else { + $parentcatlist = $category->getForMenu(); + } $this->smarty->assign('parentcatlist', $parentcatlist); $searchStr = ''; - if ($this->page == 'search' && isset($_REQUEST["id"])) - $searchStr = (string)$_REQUEST["id"]; + if ($this->page == 'search' && isset($_REQUEST["id"])) { + $searchStr = (string)$_REQUEST["id"]; + } $this->smarty->assign('header_menu_search', $searchStr); - if (isset($_REQUEST["t"])) - $this->smarty->assign('header_menu_cat', $_REQUEST["t"]); + if (isset($_REQUEST["t"])) { + $this->smarty->assign('header_menu_cat', $_REQUEST["t"]); + } $header_menu = $this->smarty->fetch('headermenu.tpl'); $this->smarty->assign('header_menu', $header_menu); } diff --git a/lib/copy_this/www/lib/postprocess.php b/lib/copy_this/www/lib/postprocess.php index cfff9aca5..db4c43835 100644 --- a/lib/copy_this/www/lib/postprocess.php +++ b/lib/copy_this/www/lib/postprocess.php @@ -92,13 +92,13 @@ class PostProcess // // Delete any audiopreviews older than site->audiopreviewprune days // - if($this->site->audiopreviewprune > 0) + if ($this->site->audiopreviewprune > 0) { - $result = $db->query(sprintf("select guid from releases where categoryid in (select id from category where parentid = ".Category::CAT_PARENT_MUSIC.") and haspreview = 2 and adddate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->audiopreviewprune)); + $result = $db->query(sprintf("select guid from releases where categoryid in (select id from category where parentid = " . Category::CAT_PARENT_MUSIC . ") and haspreview = 2 and adddate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->audiopreviewprune)); if (sizeof($result) > 0) { - echo "PostPrc : Deleting ".count($result)." audio previews older than ".$this->site->audiopreviewprune." days\n"; + echo "PostPrc : Deleting " . count($result) . " audio previews older than " . $this->site->audiopreviewprune . " days\n"; foreach ($result as $row) { $r->updateHasPreview($row["guid"], 0); @@ -110,8 +110,7 @@ class PostProcess // // Delete any releases suspected of being spam/virus // - if ($this->site->removespam != 0) - { + if ($this->site->removespam != 0) { $spamIDs = array(); // @@ -151,11 +150,11 @@ class PostProcess $result = $db->query($sql); $spamIDs = array_merge($result, $spamIDs); - if (count($spamIDs) > 0) - { + if (count($spamIDs) > 0) { echo "PostPrc : Deleting " . count($spamIDs) . " spam releases\n"; - foreach ($spamIDs as $row) - $r->delete($row["id"]); + foreach ($spamIDs as $row) { + $r->delete($row["id"]); + } } } } @@ -178,8 +177,9 @@ class PostProcess { $spotnab = new SpotNab(); $processed = $spotnab->processGID(500); - if ($processed > 0) - printf("PostPrc : Updating GID in releases table %d release(s) updated\n", $processed); + if ($processed > 0) { + printf("PostPrc : Updating GID in releases table %d release(s) updated\n", $processed); + } $spotnab->auto_post_discovery(); $spotnab->fetch_discovery(); $spotnab->fetch(); @@ -241,8 +241,7 @@ class PostProcess $sql = sprintf("select id from releases where categoryid = %d", Category::CAT_NOT_DETERMINED); $result = $db->query($sql); $rescount = sizeof($result); - if ($rescount > 0) - { + if ($rescount > 0) { echo "PostPrc : Attempting to fix " . $rescount . " uncategorised release(s)\n"; $sql = sprintf("update releases inner join releasevideo rv on rv.releaseid = releases.id set releases.categoryid = %d where imdbid is not null and categoryid = %d and videocodec = 'XVID'", Category::CAT_MOVIE_SD, Category::CAT_NOT_DETERMINED); @@ -261,21 +260,18 @@ class PostProcess */ public function processTv() { - if ($this->site->lookupanidb == 1) - { + if ($this->site->lookupanidb == 1) { $anidb = new AniDB($this->echooutput); $anidb->animetitlesUpdate(); $anidb->processAnimeReleases(); } - if ($this->site->lookuptvrage == 1) - { + if ($this->site->lookuptvrage == 1) { $tvrage = new TVRage($this->echooutput); $tvrage->processTvReleases(($this->site->lookuptvrage == 1)); } - if ($this->site->lookupthetvdb == 1) - { + if ($this->site->lookupthetvdb == 1) { $thetvdb = new TheTVDB($this->echooutput); $thetvdb->processReleases(); } @@ -287,20 +283,20 @@ class PostProcess public function processOtherMiscCategory() { $p = null; - if($this->site->updatecleanup == 1) + if ($this->site->updatecleanup == 1) { $p = new Parsing(false, true, false); $p->cleanup(); } - if($this->site->updateparsing == 1) + if ($this->site->updateparsing == 1) { if ($p == null) $p = new Parsing(false, true, false); $p->process(); } - if($this->site->removespecial == 1) + if ($this->site->removespecial == 1) { if ($p == null) $p = new Parsing(false, true, false); @@ -322,13 +318,13 @@ class PostProcess $processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false; $tmpPath = $this->site->tmpunrarpath; - if (substr($tmpPath, -strlen('/')) != '/') - { + if (substr($tmpPath, -strlen('/')) != '/') { $tmpPath = $tmpPath . '/'; } - if (!file_exists($tmpPath)) - mkdir($tmpPath, 0766, true); + if (!file_exists($tmpPath)) { + mkdir($tmpPath, 0766, true); + } $db = new DB(); $nntp = new Nntp; @@ -344,13 +340,11 @@ class PostProcess $result = $db->query($sql); $iteration = $rescount = sizeof($result); - if ($rescount > 0) - { + if ($rescount > 0) { echo "PostPrc : Performing additional post processing on last " . $rescount . " releases ..."; $nntpconnected = false; - foreach ($result as $rel) - { + foreach ($result as $rel) { echo $iteration-- . "."; // Per release defaults @@ -358,8 +352,9 @@ class PostProcess $blnTookMediainfo = false; $blnTookSample = ($rel['disablepreview'] == 1) ? true : false; //only attempt sample if not disabled - if ($blnTookSample) - $db->queryExec(sprintf("update releases set haspreview = 0 where id = %d", $rel['id'])); + if ($blnTookSample) { + $db->queryExec(sprintf("update releases set haspreview = 0 where id = %d", $rel['id'])); + } // // Go through the binaries for this release looking for a rar, a sample, and a mediafile @@ -376,15 +371,15 @@ class PostProcess continue; } - foreach($nzbInfo->nzb as $nzbsubject) + foreach ($nzbInfo->nzb as $nzbsubject) { if (preg_match("/\w\.r00/i", $nzbsubject['subject'])) - $norar= 1; + $norar = 1; } } // attempt to process video sample file - if(!empty($nzbInfo->samplefiles) && $processVideoSample && $blnTookSample === false) + if (!empty($nzbInfo->samplefiles) && $processVideoSample && $blnTookSample === false) { $sampleFile = $nzbInfo->samplefiles[0]; //first detected sample $sampleMsgids = array_slice($sampleFile['segments'], 0, 1); //get first segment, increase to get more of the sample @@ -413,34 +408,34 @@ class PostProcess } // attempt to process loose media file - if (!empty($nzbInfo->mediafiles) && (($processVideoSample && $blnTookSample === false) || $processMediainfo)) - { + if (!empty($nzbInfo->mediafiles) && (($processVideoSample && $blnTookSample === false) || $processMediainfo)) { $mediaFile = $nzbInfo->mediafiles[0]; //first detected media file $mediaMsgids = array_slice($mediaFile['segments'], 0, 2); //get first two segments $mediaGroup = $mediaFile['groups'][0]; //echo "PostPrc : Fetching ".implode($mediaMsgids, ', ')." from {$mediaGroup}\n"; - if (!$nntpconnected) - $nntpconnected = $nntp->doConnect(); + if (!$nntpconnected) { + $nntpconnected = $nntp->doConnect(); + } $mediaBinary = $nntp->getMessages($mediaGroup, $mediaMsgids); - if ($mediaBinary === false) - echo "\nPostPrc : Couldnt fetch media file\n"; - else - { + if ($mediaBinary === false) { + echo "\nPostPrc : Couldnt fetch media file\n"; + } else { $mediafile = $tmpPath . 'sample.avi'; file_put_contents($mediafile, $mediaBinary); - if ($processVideoSample && $blnTookSample === false) - { + if ($processVideoSample && $blnTookSample === false) { $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); - if ($blnTookSample) - $this->updateReleaseHasPreview($rel['guid']); + if ($blnTookSample) { + $this->updateReleaseHasPreview($rel['guid']); + } } - if ($processMediainfo) - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + if ($processMediainfo) { + $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + } unlink($mediafile); } @@ -448,48 +443,47 @@ class PostProcess } // attempt to process audio sample file - if (!empty($nzbInfo->audiofiles) && $processAudioSample && $blnTookSample === false) - { + if (!empty($nzbInfo->audiofiles) && $processAudioSample && $blnTookSample === false) { $audioFile = $nzbInfo->audiofiles[0]; //first detected audio file $audioMsgids = array_slice($audioFile['segments'], 0, 1); //get first segment $audioGroup = $audioFile['groups'][0]; //echo "PostPrc : Fetching ".implode($audioMsgids, ', ')." from {$audioGroup}\n"; - if (!$nntpconnected) - $nntpconnected = $nntp->doConnect(); + if (!$nntpconnected) { + $nntpconnected = $nntp->doConnect(); + } $audioBinary = $nntp->getMessages($audioGroup, $audioMsgids); - if ($audioBinary === false) - echo "\nPostPrc : Couldnt fetch audio sample\n"; - else - { + if ($audioBinary === false) { + echo "\nPostPrc : Couldnt fetch audio sample\n"; + } else { $audiofile = $tmpPath . 'sample.mp3'; file_put_contents($audiofile, $audioBinary); $blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']); - if ($blnTookSample !== false) - $this->updateReleaseHasPreview($rel['guid'], 2); + if ($blnTookSample !== false) { + $this->updateReleaseHasPreview($rel['guid'], 2); + } - if ($processMediainfo) - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + if ($processMediainfo) { + $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + } - if ($this->site->lamepath != "") - $this->lameAudioSample($this->site->lamepath, $rel['guid']); + if ($this->site->lamepath != "") { + $this->lameAudioSample($this->site->lamepath, $rel['guid']); + } unlink($audiofile); } unset($audioBinary); } - if (!empty($nzbInfo->rarfiles) && ($this->site->checkpasswordedrar > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo)) - { + if (!empty($nzbInfo->rarfiles) && ($this->site->checkpasswordedrar > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo)) { $mysqlkeepalive = 0; - foreach ($nzbInfo->rarfiles as $rarFile) - { + foreach ($nzbInfo->rarfiles as $rarFile) { //dont process any more rars if a passworded rar has been detected and the site is set to automatically delete them - if ($this->site->deletepasswordedrelease == 1 && max($passStatus) == Releases::PASSWD_RAR) - { + if ($this->site->deletepasswordedrelease == 1 && max($passStatus) == Releases::PASSWD_RAR) { echo "-Skipping processing of rar {$rarFile['subject']} as this release has already been marked as passworded.\n"; continue; } @@ -498,28 +492,24 @@ class PostProcess $rarGroup = $rarFile['groups'][0]; //echo "PostPrc : Fetching ".implode($rarMsgids, ', ')." from {$rarGroup} (".++$mysqlkeepalive.")\n"; - if (!$nntpconnected) - $nntpconnected = $nntp->doConnect(); + if (!$nntpconnected) { + $nntpconnected = $nntp->doConnect(); + } $fetchedBinary = $nntp->getMessages($rarGroup, $rarMsgids); - if ($fetchedBinary === false) - { + if ($fetchedBinary === false) { //echo "\nPostPrc : Failed fetching rar file\n"; $db->queryExec(sprintf("update releases set passwordstatus = passwordstatus - 1 where id = %d", $rel['id'])); continue; - } - else - { + } else { $relFiles = $this->processReleaseFiles($fetchedBinary, $rel['id']); - if ($this->site->checkpasswordedrar > 0 && $processPasswords) - { + if ($this->site->checkpasswordedrar > 0 && $processPasswords) { $passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->site->unrarpath, $this->site->checkpasswordedrar); } // we need to unrar the fetched binary if checkpasswordedrar wasnt 2 - if ($this->site->checkpasswordedrar < 2 && $processPasswords) - { + if ($this->site->checkpasswordedrar < 2 && $processPasswords) { $rarfile = $tmpPath . 'rarfile.rar'; file_put_contents($rarfile, $fetchedBinary); $execstring = '"' . $this->site->unrarpath . '" e -ai -ep -c- -id -r -kb -p- -y -inul "' . $rarfile . '" "' . $tmpPath . '"'; @@ -527,63 +517,59 @@ class PostProcess unlink($rarfile); } - if ($processVideoSample && $blnTookSample === false) - { + if ($processVideoSample && $blnTookSample === false) { $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); - if ($blnTookSample) - $this->updateReleaseHasPreview($rel['guid']); + if ($blnTookSample) { + $this->updateReleaseHasPreview($rel['guid']); + } } $blnTookAudioSample = false; - if ($processAudioSample && $blnTookSample === false) - { + if ($processAudioSample && $blnTookSample === false) { $blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']); - if ($blnTookSample) - { + if ($blnTookSample) { $blnTookAudioSample = true; $this->updateReleaseHasPreview($rel['guid'], 2); } } - if ($processMediainfo && $blnTookMediainfo === false) - { + if ($processMediainfo && $blnTookMediainfo === false) { $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); } // // Has to be done after mediainfo // - if ($blnTookAudioSample && $this->site->lamepath != "") - $this->lameAudioSample($this->site->lamepath, $rel['guid']); + if ($blnTookAudioSample && $this->site->lamepath != "") { + $this->lameAudioSample($this->site->lamepath, $rel['guid']); + } - if ($mysqlkeepalive % 25 == 0) - $db->query("select 1"); + if ($mysqlkeepalive % 25 == 0) { + $db->query("select 1"); + } } //clean up all files - foreach (glob($tmpPath . '*') as $v) - { + foreach (glob($tmpPath . '*') as $v) { unlink($v); } } //end foreach msgid - } - elseif (empty($nzbInfo->rarfiles) && $norar == 1) - { + } elseif (empty($nzbInfo->rarfiles) && $norar == 1) { $passStatus[] = Releases::PASSWD_POTENTIAL; } $hpsql = ''; - if (!$blnTookSample) - $hpsql = ', haspreview = 0'; + if (!$blnTookSample) { + $hpsql = ', haspreview = 0'; + } $sql = sprintf("update releases set passwordstatus = %d %s where id = %d", max($passStatus), $hpsql, $rel["id"]); $db->queryExec($sql); } //end foreach result - if ($nntpconnected) - { + if ($nntpconnected) { $nntp->doQuit(); } @@ -614,7 +600,7 @@ class PostProcess { if (isset($file['name'])) { - $rf->add($relid, utf8_encode($file['name']), (isset($file['size']) ? $file['size'] : ""), (isset($file['date']) ? $file['date'] : ""), (isset($file['pass']) ? $file['pass'] : "") ); + $rf->add($relid, utf8_encode($file['name']), (isset($file['size']) ? $file['size'] : ""), (isset($file['date']) ? $file['date'] : ""), (isset($file['pass']) ? $file['pass'] : "")); $retval[] = $file['name']; } } @@ -639,37 +625,28 @@ class PostProcess $rarfile = $tmpPath . 'rarfile.rar'; file_put_contents($rarfile, $fetchedBinary); - if ($rar->open($rarfile)) - { + if ($rar->open($rarfile)) { $rarsummary = $rar->getSummary(true, false); - if ((isset($rarsummary["is_encrypted"]) && $rarsummary["is_encrypted"] != 0) || !empty($rar->isEncrypted)) - { + if ((isset($rarsummary["is_encrypted"]) && $rarsummary["is_encrypted"] != 0) || !empty($rar->isEncrypted)) { $passStatus = Releases::PASSWD_RAR; - } - else - { + } else { $files = $rar->getArchiveFileList(); - if ($files !== false) - { - foreach ($files as $file) - { - if (isset($file['pass']) && isset($file["name"])) - { + if ($files !== false) { + foreach ($files as $file) { + if (isset($file['pass']) && isset($file["name"])) { $filecount++; // // individual file rar passworded // - if ($file['pass'] == true || preg_match($definetlypasswordedfileregex, $file["name"])) - { + if ($file['pass'] == true || preg_match($definetlypasswordedfileregex, $file["name"])) { $passStatus = Releases::PASSWD_RAR; } // // individual file looks suspect // - elseif (preg_match($potentiallypasswordedfileregex, $file["name"]) && $passStatus != Releases::PASSWD_RAR) - { + elseif (preg_match($potentiallypasswordedfileregex, $file["name"]) && $passStatus != Releases::PASSWD_RAR) { $passStatus = Releases::PASSWD_POTENTIAL; } } @@ -680,14 +657,11 @@ class PostProcess // // Deep Checking // - if ($checkpasswordedrar == 2) - { + if ($checkpasswordedrar == 2) { $israr = $this->isRar($rarfile); - for ($i = 0; $i < sizeof($israr); $i++) - { - if (preg_match('/\\\\/', $israr[$i])) - { + for ($i = 0; $i < sizeof($israr); $i++) { + if (preg_match('/\\\\/', $israr[$i])) { $israr[$i] = ltrim((strrchr($israr[$i], "\\")), "\\"); } } @@ -702,22 +676,22 @@ class PostProcess // the rar file deleted, now to loop through the files and recursively unrar // if any of those are rars, we don't trust their names and we test every file // for the rar header - for ($i = 0; $i < sizeof($israr); $i++) - { + for ($i = 0; $i < sizeof($israr); $i++) { // even though its in the rar filelist there may not have been enough data // to extract this file so dont attempt to read the file if it doesnt exist - if (!file_exists($tmpPath . $israr[$i])) - continue; + if (!file_exists($tmpPath . $israr[$i])) { + continue; + } $tmp = $this->isRar($tmpPath . $israr[$i]); - if (is_array($tmp)) - // it's a rar + if (is_array($tmp)) { + // it's a rar { - for ($x = 0; $x < sizeof($tmp); $x++) - { - if (preg_match('/\\\\/', $tmp[$x])) - { + for ($x = 0; + } + $x < sizeof($tmp); $x++) { + if (preg_match('/\\\\/', $tmp[$x])) { $tmp[$x] = ltrim((strrchr($tmp[$x], "\\")), "\\"); } $israr[] = $tmp[$x]; @@ -726,11 +700,8 @@ class PostProcess $execstring = '"' . $unrarPath . '" e -ai -ep -c- -id -r -kb -p- -y -inul "' . $tmpPath . $israr[$i] . '" "' . $tmpPath . '"'; $output2 = runCmd($execstring, false, true); @unlink($tmpPath . $israr[$i]); - } - else - { - if ($tmp == 1 || $tmp == 2) - { + } else { + if ($tmp == 1 || $tmp == 2) { $passStatus = Releases::PASSWD_RAR; @unlink($tmpPath . $israr[$i]); } @@ -757,26 +728,21 @@ class PostProcess // returns array of files in the rar if normal rar $filelist = array(); $rar = new ArchiveInfo; - if ($rar->open($rarfile)) - { - if (!empty($rar->isEncrypted)) - { + if ($rar->open($rarfile)) { + if (!empty($rar->isEncrypted)) { return 1; - } - else - { + } else { $files = $rar->getArchiveFileList(); - foreach ($files as $file) - { - if (isset($file['pass']) && isset($file["name"])) - { + foreach ($files as $file) { + if (isset($file['pass']) && isset($file["name"])) { $filelist[] = $file['name']; - if ($file['pass'] == true) - // + if ($file['pass'] == true) { + // // individual file rar passworded // { return 2; + } // passworded } } @@ -797,32 +763,24 @@ class PostProcess { $retval = false; $mediafiles = glob($ramdrive . '*.*'); - if (is_array($mediafiles)) - { - foreach ($mediafiles as $mediafile) - { - if (preg_match("/\.(" . $this->mediafileregex . '|' . $this->audiofileregex . ")$/i", $mediafile)) - { + if (is_array($mediafiles)) { + foreach ($mediafiles as $mediafile) { + if (preg_match("/\.(" . $this->mediafileregex . '|' . $this->audiofileregex . ")$/i", $mediafile)) { $execstring = '"' . $mediainfo . '" --Output=XML "' . $mediafile . '"'; $xmlarray = runCmd($execstring); - if (is_array($xmlarray)) - { + if (is_array($xmlarray)) { $xmlarray = implode("\n", $xmlarray); $re = new ReleaseExtra(); $re->addFull($releaseID, $xmlarray); $re->addFromXml($releaseID, $xmlarray); $retval = true; - } - else - { + } else { echo "PostPrc : Failed to process mediainfo for " . $mediafile . " release (" . $releaseID . ")\n"; } } } - } - else - { + } else { echo "PostPrc: Couldn't open temp drive " . $ramdrive . "\n"; } return $retval; @@ -837,12 +795,9 @@ class PostProcess $retval = false; $samplefiles = glob($ramdrive . '*.*'); - if (is_array($samplefiles)) - { - foreach ($samplefiles as $samplefile) - { - if (preg_match("/\.(" . $this->mediafileregex . ")$/i", $samplefile)) - { + if (is_array($samplefiles)) { + foreach ($samplefiles as $samplefile) { + if (preg_match("/\.(" . $this->mediafileregex . ")$/i", $samplefile)) { //1.0 //$execstring = '"'.$ffmpeginfo.'" -sameq -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"'; @@ -853,18 +808,18 @@ class PostProcess //$execstring = '"'.$ffmpeginfo.'" -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"'; //1.x - $execstring = '"'.$ffmpeginfo.'" -q:v 0 -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"'; + $execstring = '"' . $ffmpeginfo . '" -q:v 0 -i "' . $samplefile . '" -vframes 300 "' . $ramdrive . 'zzzz%03d.jpg"'; runCmd($execstring, false, true); - $all_files = scandir($ramdrive,1); - if(preg_match("/zzzz\d{3}\.jpg/",$all_files[1])) + $all_files = scandir($ramdrive, 1); + if (preg_match("/zzzz\d{3}\.jpg/", $all_files[1])) { - $ri->saveImage($releaseguid.'_thumb', $ramdrive.$all_files[1], $ri->imgSavePath, 800, 600); + $ri->saveImage($releaseguid . '_thumb', $ramdrive . $all_files[1], $ri->imgSavePath, 800, 600); $retval = true; } //clean up all files - foreach(glob($ramdrive.'*.jpg') as $v) + foreach (glob($ramdrive . '*.jpg') as $v) { unlink($v); } @@ -886,22 +841,22 @@ class PostProcess $returnval = false; $minacceptableencodefilesize = 10000; - $samplefile = $this->mp3SavePath.$releaseguid.'.mp3'; - $samplefileogg = $this->mp3SavePath.$releaseguid.'.ogg'; + $samplefile = $this->mp3SavePath . $releaseguid . '.mp3'; + $samplefileogg = $this->mp3SavePath . $releaseguid . '.ogg'; $ffmpeginfo = $this->site->ffmpegpath; if (file_exists($samplefile)) { - $outfile = $this->mp3SavePath.$releaseguid.'_l.mp3'; - $outfileogg = $this->mp3SavePath.$releaseguid.'_l.ogg'; + $outfile = $this->mp3SavePath . $releaseguid . '_l.mp3'; + $outfileogg = $this->mp3SavePath . $releaseguid . '_l.ogg'; // // lame the sample down to 96kb and replace it. alternatives could be // V8 for low quality variable. // - $execstring = '"'.$lameinfo.'" -b 96 "'.$samplefile.'" "'.$outfile.'"'; - $execstringogg = '"'.$ffmpeginfo.'" -i "'.$samplefile.'" -acodec libvorbis "'.$outfileogg.'"'; + $execstring = '"' . $lameinfo . '" -b 96 "' . $samplefile . '" "' . $outfile . '"'; + $execstringogg = '"' . $ffmpeginfo . '" -i "' . $samplefile . '" -acodec libvorbis "' . $outfileogg . '"'; $output = runCmd($execstring, false, true); $output = runCmd($execstringogg, false, true); @@ -910,24 +865,20 @@ class PostProcess // if it creates a file thats surprisingly small, then ignore it and retain // original // - if (file_exists($outfile)) - { - if (filesize($outfile) < $minacceptableencodefilesize) - unlink($outfile); - else - { + if (file_exists($outfile)) { + if (filesize($outfile) < $minacceptableencodefilesize) { + unlink($outfile); + } else { unlink($samplefile); rename($outfile, $samplefile); $returnval = true; } } - if (file_exists($outfileogg)) - { - if (filesize($outfileogg) < $minacceptableencodefilesize) - unlink($outfileogg); - else - { + if (file_exists($outfileogg)) { + if (filesize($outfileogg) < $minacceptableencodefilesize) { + unlink($outfileogg); + } else { rename($outfileogg, $samplefileogg); $returnval = true; } @@ -945,21 +896,17 @@ class PostProcess $retval = false; $audiofiles = glob($ramdrive . '*.*'); - if (is_array($audiofiles)) - { - foreach ($audiofiles as $audiofile) - { - if (preg_match("/\.(" . $this->audiofileregex . ")$/i", $audiofile)) - { - if (copy($audiofile, $this->mp3SavePath . $releaseguid . '.mp3') !== false) - $retval = true; - else - echo "PostPrc : Failed to get audio sample from " . $audiofile . "\n"; + if (is_array($audiofiles)) { + foreach ($audiofiles as $audiofile) { + if (preg_match("/\.(" . $this->audiofileregex . ")$/i", $audiofile)) { + if (copy($audiofile, $this->mp3SavePath . $releaseguid . '.mp3') !== false) { + $retval = true; + } else { + echo "PostPrc : Failed to get audio sample from " . $audiofile . "\n"; + } } } - } - else - { + } else { echo "PostPrc: Couldn't open temp drive " . $ramdrive . "\n"; } return $retval; @@ -971,8 +918,9 @@ class PostProcess public function deleteAudioSample($releaseguid) { $preview = $this->mp3SavePath . $releaseguid . '.mp3'; - if (file_exists($preview)) - unlink($preview); + if (file_exists($preview)) { + unlink($preview); + } } /** diff --git a/lib/copy_this/www/lib/powerprocess.php b/lib/copy_this/www/lib/powerprocess.php index dd5a19569..3469f30ee 100644 --- a/lib/copy_this/www/lib/powerprocess.php +++ b/lib/copy_this/www/lib/powerprocess.php @@ -40,7 +40,8 @@ declare(ticks = 1); * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -class PowerProcess { +class PowerProcess +{ const CALLBACK_STOP_PROPOGATION = -1; const CALLBACK_IGNORE = 0; const CALLBACK_CONTINUE = 1; @@ -177,6 +178,9 @@ class PowerProcess { SIGUSR2 // User-Defined 2 ); + /** + * @param string $signal + */ static public function SignalName($signal) { switch ($signal) { @@ -534,7 +538,8 @@ class PowerProcess { * * @param boolean $exit When set to true, Shutdown causes the script to exit */ - public function Shutdown($exit = false) { + public function Shutdown($exit = false) + { $this->Log("Initiating shutdown", true); while ($this->ThreadCount()) { @@ -690,7 +695,8 @@ class PowerProcess { * * @return null|boolean */ - private function Daemonize() { + private function Daemonize() + { $this->Log("Attempting to Daemonize", true); // First need to fork @@ -699,8 +705,14 @@ class PowerProcess { // Tick to catch signals $this->Tick(); - if ($pid < 0) exit; // Error - if ($pid) exit; // Parent + if ($pid < 0) { + exit; + } + // Error + if ($pid) { + exit; + } + // Parent $this->parentSID = posix_setsid(); @@ -747,7 +759,9 @@ class PowerProcess { $this->Log("SIGTERM callback registered", true); // Install the signal handler - foreach ($this->signalArray as $signal) $this->RegisterCallback($signal); + foreach ($this->signalArray as $signal) { + $this->RegisterCallback($signal); + } $this->Log("Signal Dispatcher installed", true); } diff --git a/lib/copy_this/www/lib/predb.php b/lib/copy_this/www/lib/predb.php index ec03e7dbc..90146f7d2 100644 --- a/lib/copy_this/www/lib/predb.php +++ b/lib/copy_this/www/lib/predb.php @@ -105,27 +105,27 @@ class PreDB { $db = new DB(); - if ($this->echooutput) - echo "Predb : Updating releases with pre data\n"; + if ($this->echooutput) { + echo "Predb : Updating releases with pre data\n"; + } $matched = 0; $releasesQuery = $db->queryDirect(sprintf('SELECT id, searchname FROM releases WHERE preid IS NULL AND adddate > DATE_SUB(NOW(), INTERVAL %d DAY)', $daysback)); - while ($arr = $db->getAssocArray($releasesQuery)) - { + while ($arr = $db->getAssocArray($releasesQuery)) { $arr['searchname'] = str_replace(' ', '_', $arr['searchname']); $sql = sprintf("SELECT id FROM predb WHERE dirname = %s LIMIT 1", $db->escapeString($arr['searchname'])); $predbQuery = $db->queryOneRow($sql); - if ($predbQuery) - { + if ($predbQuery) { $db->queryExec(sprintf('UPDATE releases SET preid = %d WHERE id = %d', $predbQuery['id'], $arr['id'])); $matched++; } } - if ($this->echooutput) - echo "Predb : Matched pre data to " . $matched . " releases\n"; + if ($this->echooutput) { + echo "Predb : Matched pre data to " . $matched . " releases\n"; + } } @@ -136,8 +136,7 @@ class PreDB */ public function updatePreDB($db, $preArray) { - if (!preg_match('/^(UN)?((MOD)?NUKED?|DELPRE)$/', $preArray['category'])) - { + if (!preg_match('/^(UN)?((MOD)?NUKED?|DELPRE)$/', $preArray['category'])) { $db->queryExec(sprintf('INSERT INTO predb (ctime, dirname, category, filesize, filecount, filename) VALUES (%d, %s, %s, %F, %d, %s) @@ -200,61 +199,61 @@ class PreDB */ public function nzpreUpdate() { - require_once(WWW_DIR."/lib/nntp.php"); + require_once(WWW_DIR . "/lib/nntp.php"); $s = new Sites(); $site = $s->get(); - if(empty($site->nzpregroup) || empty($site->nzpresubject) || empty($site->nzpreposter) || empty($site->nzprefield) || empty($site->nzprekey)) { + if (empty($site->nzpregroup) || empty($site->nzpresubject) || empty($site->nzpreposter) || empty($site->nzprefield) || empty($site->nzprekey)) { return false; } - if($this->echooutput) { + if ($this->echooutput) { echo "Predb : Checking for new pre data "; } $db = new DB(); $nntp = new Nntp(); - if(!$nntp->doConnect()) { + if (!$nntp->doConnect()) { echo "Failed to get NNTP connection\n"; return false; } $ret = $groupData = $nntp->selectGroup($site->nzpregroup); - if($nntp->isError($ret)) { - echo "Predb : Error ".$ret->getMessage()."\n"; + if ($nntp->isError($ret)) { + echo "Predb : Error " . $ret->getMessage() . "\n"; return false; } - $ret = $groupMsgs = $nntp->getOverview(($groupData['last']-(!empty($site->nzprearticles) ? $site->nzprearticles : 500)).'-'.$groupData['last']); - if($nntp->isError($ret)) { - echo "Predb : Error ".$ret->getMessage()."\n"; + $ret = $groupMsgs = $nntp->getOverview(($groupData['last'] - (!empty($site->nzprearticles) ? $site->nzprearticles : 500)) . '-' . $groupData['last']); + if ($nntp->isError($ret)) { + echo "Predb : Error " . $ret->getMessage() . "\n"; return false; } $added_updated = 0; $nzprekey = $site->nzprekey; - while(strlen($nzprekey) < 1024) { - $nzprekey = $nzprekey.$nzprekey; + while (strlen($nzprekey) < 1024) { + $nzprekey = $nzprekey . $nzprekey; } $cnt = !empty($site->nzprearticles) ? $site->nzprearticles : 500; - foreach($groupMsgs as $groupMsg) { - if ($cnt%50==0 && $cnt != 0 && $this->echooutput) { - echo $cnt.".."; + foreach ($groupMsgs as $groupMsg) { + if ($cnt % 50 == 0 && $cnt != 0 && $this->echooutput) { + echo $cnt . ".."; } $cnt--; - if(preg_match('/^'.$site->nzpresubject.'$/', $groupMsg['Subject']) && preg_match('/^'.$site->nzpreposter.'$/', $groupMsg['From'])) { + if (preg_match('/^' . $site->nzpresubject . '$/', $groupMsg['Subject']) && preg_match('/^' . $site->nzpreposter . '$/', $groupMsg['From'])) { $ret = $msgHeader = $nntp->getHeader($groupMsg['Message-ID']); - if($nntp->isError($ret)) { + if ($nntp->isError($ret)) { continue; } - for($i=0; $i < count($msgHeader); $i++) { - if(preg_match('/^'.$site->nzprefield.': /', $msgHeader[$i])) { - if($nzpreParse = $this->nzpreParse(str_replace($site->nzprefield.': ', '', $msgHeader[$i]), $nzprekey)) { + for ($i = 0; $i < count($msgHeader); $i++) { + if (preg_match('/^' . $site->nzprefield . ': /', $msgHeader[$i])) { + if ($nzpreParse = $this->nzpreParse(str_replace($site->nzprefield . ': ', '', $msgHeader[$i]), $nzprekey)) { if ($this->updatePreDB($db, $nzpreParse)) { $added_updated++; } @@ -268,7 +267,8 @@ class PreDB $nntp->disconnect(); - if ($this->echooutput) - echo "\nPredb : Added/Updated " . $added_updated . " records\n"; + if ($this->echooutput) { + echo "\nPredb : Added/Updated " . $added_updated . " records\n"; + } } } diff --git a/lib/copy_this/www/lib/recaptchalib.php b/lib/copy_this/www/lib/recaptchalib.php index 50c08f8b4..759846725 100644 --- a/lib/copy_this/www/lib/recaptchalib.php +++ b/lib/copy_this/www/lib/recaptchalib.php @@ -44,13 +44,13 @@ define("RECAPTCHA_VERIFY_SERVER", "www.google.com"); * @param $data - array of string elements to be encoded * @return string - encoded request */ -function _recaptcha_qsencode ($data) { +function _recaptcha_qsencode($data) { $req = ""; - foreach ( $data as $key => $value ) - $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; + foreach ($data as $key => $value) + $req .= $key . '=' . urlencode(stripslashes($value)) . '&'; // Cut the last '&' - $req=substr($req,0,strlen($req)-1); + $req = substr($req, 0, strlen($req) - 1); return $req; } @@ -67,7 +67,7 @@ function _recaptcha_qsencode ($data) { function _recaptcha_http_post($host, $path, $data, $port = 80) { - $req = _recaptcha_qsencode ($data); + $req = _recaptcha_qsencode($data); $http_request = "POST $path HTTP/1.0\r\n"; $http_request .= "Host: $host\r\n"; @@ -78,13 +78,13 @@ function _recaptcha_http_post($host, $path, $data, $port = 80) $http_request .= $req; $response = ''; - if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { + if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) { die ('Could not open socket'); } fwrite($fs, $http_request); - while ( !feof($fs) ) + while (!feof($fs)) $response .= fgets($fs, 1160); // One TCP-IP packet fclose($fs); $response = explode("\r\n\r\n", $response, 2); @@ -119,7 +119,7 @@ function recaptcha_get_html($pubkey, $error = null, $use_ssl = false) if ($error) { $errorpart = "&error=" . $error; } - return ' + return '