diff --git a/Changelog b/Changelog index 3c9630bc8..d781df250 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-04-20 DariusIII + * Chg: Update XXX class for better PHP7 support * Fix: Properly update anidb_episodes table on anidb updates 2017-04-19 DariusIII * Fix: Fix bad logic for namefixer release update function diff --git a/nntmux/XXX.php b/nntmux/XXX.php index 53ddefca6..cffa099bf 100755 --- a/nntmux/XXX.php +++ b/nntmux/XXX.php @@ -84,7 +84,7 @@ class XXX $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); $this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage($this->pdo)); - $this->movieqty = (Settings::value('..maxxxxprocessed') != '') ? Settings::value('..maxxxxprocessed') : 100; + $this->movieqty = (Settings::value('..maxxxxprocessed') !== '') ? Settings::value('..maxxxxprocessed') : 100; $this->showPasswords = Releases::showPasswords(); $this->debug = NN_DEBUG; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); @@ -119,7 +119,7 @@ class XXX */ public function getXXXInfo($xxxid) { - return $this->pdo->queryOneRow(sprintf("SELECT *, UNCOMPRESS(plot) AS plot FROM xxxinfo WHERE id = %d", $xxxid)); + return $this->pdo->queryOneRow(sprintf('SELECT *, UNCOMPRESS(plot) AS plot FROM xxxinfo WHERE id = %d', $xxxid)); } /** @@ -130,7 +130,7 @@ class XXX * * @return array */ - public function getRange($start, $num) + public function getRange($start, $num): array { return $this->pdo->query( sprintf(' @@ -148,7 +148,7 @@ class XXX * * @return int */ - public function getCount() + public function getCount(): int { $res = $this->pdo->queryOneRow('SELECT COUNT(id) AS num FROM xxxinfo'); return ($res === false ? 0 : $res['num']); @@ -166,10 +166,10 @@ class XXX * * @return array */ - public function getXXXRange($cat, $start, $num, $orderBy, $maxAge = -1, $excludedCats = []) + public function getXXXRange($cat, $start, $num, $orderBy, $maxAge = -1, array $excludedCats = []): array { $catsrch = ''; - if (count($cat) > 0 && $cat[0] != -1) { + if (count($cat) > 0 && $cat[0] !== -1) { $catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat); } @@ -259,7 +259,7 @@ class XXX ); $return = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM); if (!empty($return)){ - $return[0]['_totalcount'] = (isset($xxxmovies['total']) ? $xxxmovies['total'] : 0); + $return[0]['_totalcount'] = $xxxmovies['total'] ?? 0; } return $return; } @@ -271,9 +271,9 @@ class XXX * * @return array */ - protected function getXXXOrder($orderBy) + protected function getXXXOrder($orderBy): array { - $orderArr = explode('_', (($orderBy == '') ? 'MAX(r.postdate)' : $orderBy)); + $orderArr = explode('_', (($orderBy === '') ? 'MAX(r.postdate)' : $orderBy)); switch ($orderArr[0]) { case 'title': $orderField = 'xxx.title'; @@ -284,7 +284,7 @@ class XXX break; } - return [$orderField, ((isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1])) ? $orderArr[1] : 'desc')]; + return [$orderField, isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1]) ? $orderArr[1] : 'desc']; } /** @@ -292,7 +292,7 @@ class XXX * * @return array */ - public function getXXXOrdering() + public function getXXXOrdering(): array { return ['title_asc', 'title_desc', 'name_asc', 'name_desc', 'size_asc', 'size_desc', 'posted_asc', 'posted_desc', 'cat_asc', 'cat_desc']; } @@ -300,17 +300,17 @@ class XXX /** * @return string */ - protected function getBrowseBy() + protected function getBrowseBy(): string { $browseBy = ' '; $browseByArr = ['title', 'director', 'actors', 'genre', 'id']; foreach ($browseByArr as $bb) { if (isset($_REQUEST[$bb]) && !empty($_REQUEST[$bb])) { $bbv = stripslashes($_REQUEST[$bb]); - if ($bb == "genre") { + if ($bb === 'genre') { $bbv = $this->getGenreID($bbv); } - if ($bb == 'id') { + if ($bb === 'id') { $browseBy .= 'AND xxx.' . $bb . '=' . $bbv; } else { $browseBy .= 'AND xxx.' . $bb . ' ' . $this->pdo->likeString($bbv, true, true); @@ -328,9 +328,9 @@ class XXX * * @return string */ - public function makeFieldLinks($data, $field) + public function makeFieldLinks($data, $field): string { - if (!isset($data[$field]) || $data[$field] == '') { + if (empty($data[$field])) { return ''; } @@ -338,12 +338,12 @@ class XXX $newArr = []; $i = 0; foreach ($tmpArr as $ta) { - if (trim($ta) == '') { + if (trim($ta) === '') { continue; } - if ($field == "genre" ) { + if ($field === 'genre' ) { $ta = $this->getGenres(true,$ta); - $ta = $ta["title"]; + $ta = $ta['title']; } if ($i > 7) { break; @@ -375,15 +375,15 @@ class XXX public function update( $id = '', $title = '', $tagLine = '', $plot = '', $genre = '', $director = '', $actors = '', $extras = '', $productInfo = '', $trailers = '', $directUrl = '', $classUsed = '', $cover = '', $backdrop = '' - ) + ): void { if (!empty($id)) { $this->pdo->queryExec( - sprintf("UPDATE xxxinfo SET title = %s, tagline = %s, plot = COMPRESS(%s), genre = %s, director = %s, + sprintf('UPDATE xxxinfo SET title = %s, tagline = %s, plot = COMPRESS(%s), genre = %s, director = %s, actors = %s, extras = %s, productinfo = %s, trailers = %s, directurl = %s, classused = %s, cover = %d, backdrop = %d, updateddate = NOW() - WHERE id = %d", + WHERE id = %d', $this->pdo->escapeString($title), $this->pdo->escapeString($tagLine), $this->pdo->escapeString($plot), @@ -410,7 +410,7 @@ class XXX * * @return bool */ - public function updateXXXInfo($xxxmovie) + public function updateXXXInfo($xxxmovie): bool { $res = false; @@ -422,35 +422,35 @@ class XXX if ($iafd->findme() !== false) { switch($iafd->classUsed) { - case "ade": + case 'ade': $mov = new ADE(); $mov->directLink = (string)$iafd->directUrl; $res = $mov->getDirect(); $res['title'] = $iafd->title; $res['directurl'] = (string)$iafd->directUrl; $this->whichclass = $iafd->classUsed; - ColorCLI::doEcho(ColorCLI::primary("Fetching XXX info from IAFD -> Adult DVD Empire")); + ColorCLI::doEcho(ColorCLI::primary('Fetching XXX info from IAFD -> Adult DVD Empire')); break; } } if ($res === false) { - $this->whichclass = "aebn"; + $this->whichclass = 'aebn'; $mov = new AEBN(); $mov->cookie = $this->cookie; $mov->searchTerm = $xxxmovie; $res = $mov->search(); if ($res === false) { - $this->whichclass = "ade"; + $this->whichclass = 'ade'; $mov = new ADE(); $mov->searchTerm = $xxxmovie; $res = $mov->search(); } if ($res === false) { - $this->whichclass = "pop"; + $this->whichclass = 'pop'; $mov = new Popporn(); $mov->cookie = $this->cookie; $mov->searchTerm = $xxxmovie; @@ -459,7 +459,7 @@ class XXX // Last in list as it doesn't have trailers if ($res === false) { - $this->whichclass = "adm"; + $this->whichclass = 'adm'; $mov = new ADM(); $mov->cookie = $this->cookie; $mov->searchTerm = $xxxmovie; @@ -472,22 +472,22 @@ class XXX if ($this->echooutput) { switch ($this->whichclass) { - case "aebn": - $fromstr = "Adult Entertainment Broadcast Network"; + case 'aebn': + $fromstr = 'Adult Entertainment Broadcast Network'; break; - case "ade": - $fromstr = "Adult DVD Empire"; + case 'ade': + $fromstr = 'Adult DVD Empire'; break; - case "pop": - $fromstr = "PopPorn"; + case 'pop': + $fromstr = 'PopPorn'; break; - case "adm": - $fromstr = "Adult DVD Marketplace"; + case 'adm': + $fromstr = 'Adult DVD Marketplace'; break; default: $fromstr = null; } - ColorCLI::doEcho(ColorCLI::primary("Fetching XXX info from: " . $fromstr)); + ColorCLI::doEcho(ColorCLI::primary('Fetching XXX info from: ' . $fromstr)); } $res = $mov->getAll(); } else { @@ -496,8 +496,6 @@ class XXX } } - $mov = []; - $mov['trailers'] = !empty($res['trailers']) ? serialize($res['trailers']) : ''; $mov['extras'] = !empty($res['extras']) ? serialize($res['extras']) : ''; $mov['productinfo'] = !empty($res['productinfo']) ? serialize($res['productinfo']) : ''; @@ -514,7 +512,7 @@ class XXX $mov['directurl'] = !empty($res['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'])){ $xxxID = $check['id']; @@ -531,11 +529,11 @@ class XXX // Insert New XXX Information if($check === false){ $xxxID = $this->pdo->queryInsert( - sprintf(" + sprintf(' INSERT INTO xxxinfo (title, tagline, plot, genre, director, actors, extras, productinfo, trailers, directurl, classused, cover, backdrop, createddate, updateddate) VALUES - (%s, %s, COMPRESS(%s), %s, %s, %s, %s, %s, %s, %s, %s, 0, 0, NOW(), NOW())", + (%s, %s, COMPRESS(%s), %s, %s, %s, %s, %s, %s, %s, %s, 0, 0, NOW(), NOW())', $this->pdo->escapeString($mov['title']), $this->pdo->escapeString($mov['tagline']), $this->pdo->escapeString($mov['plot']), @@ -585,15 +583,15 @@ class XXX * Process XXX releases where xxxinfo is 0 * */ - public function processXXXReleases() + public function processXXXReleases(): void { - $res = $this->pdo->query(sprintf(" + $res = $this->pdo->query(sprintf(' SELECT r.searchname, r.id FROM releases r WHERE r.nzbstatus = 1 AND r.xxxinfo_id = 0 %s - LIMIT %d", + LIMIT %d', $this->catWhere, $this->movieqty ) @@ -603,7 +601,7 @@ class XXX if ($movieCount > 0) { if ($this->echooutput) { - ColorCLI::doEcho(ColorCLI::header("Processing " . $movieCount . " XXX releases.")); + ColorCLI::doEcho(ColorCLI::header('Processing ' . $movieCount . ' XXX releases.')); } // Loop over releases. @@ -618,10 +616,10 @@ class XXX $this->currentRelID = $arr['id']; $movieName = $this->currentTitle; if ($this->debug && $this->echooutput) { - ColorCLI::doEcho("DB name: " . $arr['searchname'], true); + ColorCLI::doEcho('DB name: ' . $arr['searchname'], true); } if ($this->echooutput) { - ColorCLI::doEcho(ColorCLI::primaryOver("Looking up: ") . ColorCLI::headerOver($movieName), true); + ColorCLI::doEcho(ColorCLI::primaryOver('Looking up: ') . ColorCLI::headerOver($movieName), true); } $idcheck = $this->updateXXXInfo($movieName); @@ -629,7 +627,7 @@ class XXX $idcheck = (int)$check['id']; } } else { - ColorCLI::doEcho(".", true); + ColorCLI::doEcho('.', true); } $this->pdo->queryExec(sprintf('UPDATE releases SET xxxinfo_id = %d WHERE id = %d %s', $idcheck, $arr['id'], $this->catWhere)); } @@ -647,7 +645,7 @@ class XXX */ 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 %s', $this->pdo->likeString($releaseName, false, true))); } /** @@ -657,7 +655,7 @@ class XXX * * @return bool */ - protected function parseXXXSearchName($releaseName) + protected function parseXXXSearchName($releaseName): bool { $name = ''; $followingList = '[^\w]((2160|1080|480|720)(p|i)|AC3D|Directors([^\w]CUT)?|DD5\.1|(DVD|BD|BR)(Rip)?|BluRay|divx|HDTV|iNTERNAL|LiMiTED|(Real\.)?Proper|RE(pack|Rip)|Sub\.?(fix|pack)|Unrated|WEB-DL|(x|H)[-._ ]?264|xvid|[Dd][Ii][Ss][Cc](\d+|\s*\d+|\.\d+)|XXX|BTS|DirFix|Trailer|WEBRiP|NFO|(19|20)\d\d)[^\w]'; @@ -684,9 +682,8 @@ class XXX 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 { - ColorCLI::doEcho(".", false); } + ColorCLI::doEcho('.', false); } return false; @@ -699,16 +696,16 @@ class XXX * * @return array|null */ - public function getAllGenres($activeOnly = false) + public function getAllGenres($activeOnly = false): ?array { $ret = null; if ($activeOnly) { - $res = $this->pdo->query("SELECT title FROM genres WHERE disabled = 0 AND type = " . - Category::XXX_ROOT . " ORDER BY title"); + $res = $this->pdo->query('SELECT title FROM genres WHERE disabled = 0 AND type = ' . + Category::XXX_ROOT . ' ORDER BY title'); } else { - $res = $this->pdo->query("SELECT title FROM genres WHERE disabled = 1 AND type = " . - Category::XXX_ROOT . " ORDER BY title"); + $res = $this->pdo->query('SELECT title FROM genres WHERE disabled = 1 AND type = ' . + Category::XXX_ROOT . ' ORDER BY title'); } foreach ($res as $arr => $value) { @@ -721,23 +718,22 @@ class XXX * Get Genres for activeonly and/or an ID * * @param bool $activeOnly - * @param null $gid + * @param null|string $gid * * @return array|bool */ public function getGenres($activeOnly = false, $gid = null) { - if (isset($gid)) { - $gid = " AND id = " . $this->pdo->escapeString($gid) . " ORDER BY title"; + if ($gid !== null) { + $gid = ' AND id = ' . $this->pdo->escapeString($gid) . ' ORDER BY title'; } else { - $gid = " ORDER BY title"; + $gid = ' ORDER BY title'; } if ($activeOnly) { - return $this->pdo->queryOneRow("SELECT title FROM genres WHERE disabled = 0 AND type = " . Category::XXX_ROOT . $gid); - } else { - return $this->pdo->queryOneRow("SELECT title FROM genres WHERE disabled = 1 AND type = " . Category::XXX_ROOT . $gid); + return $this->pdo->queryOneRow('SELECT title FROM genres WHERE disabled = 0 AND type = ' . Category::XXX_ROOT . $gid); } + return $this->pdo->queryOneRow('SELECT title FROM genres WHERE disabled = 1 AND type = ' . Category::XXX_ROOT . $gid); } /** @@ -747,28 +743,28 @@ class XXX * * @return string - If array .. 1,2,3,4 if string .. 1 */ - private function getGenreID($arr) + private function getGenreID($arr): string { $ret = null; if (!is_array($arr)) { - $res = $this->pdo->queryOneRow("SELECT id FROM genres WHERE title = " . $this->pdo->escapeString($arr)); + $res = $this->pdo->queryOneRow('SELECT id FROM genres WHERE title = ' . $this->pdo->escapeString($arr)); if ($res !== false) { - return $res["id"]; + return $res['id']; } } foreach ($arr as $key => $value) { - $res = $this->pdo->queryOneRow("SELECT id FROM genres WHERE title = " . $this->pdo->escapeString($value)); + $res = $this->pdo->queryOneRow('SELECT id FROM genres WHERE title = ' . $this->pdo->escapeString($value)); if ($res !== false) { - $ret .= "," . $res["id"]; + $ret .= ',' . $res['id']; } else { - $ret .= "," . $this->insertGenre($value); + $ret .= ',' . $this->insertGenre($value); } } - $ret = ltrim($ret,","); - return ($ret); + $ret = ltrim($ret,','); + return $ret; } /** @@ -778,11 +774,11 @@ class XXX * * @return bool */ - private function insertGenre($genre) + private function insertGenre($genre): bool { $res = ''; - if (isset($genre)) { - $res = $this->pdo->queryInsert(sprintf("INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)", $this->pdo->escapeString($genre), Category::XXX_ROOT, 0)); + if ($genre !== null) { + $res = $this->pdo->queryInsert(sprintf('INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)', $this->pdo->escapeString($genre), Category::XXX_ROOT, 0)); } return $res; } @@ -795,22 +791,22 @@ class XXX * * @return string */ - public function insertSwf($whichclass, $res) + public function insertSwf($whichclass, $res): string { $ret = ''; - if ($whichclass === "ade") { + if ($whichclass === 'ade') { if (!empty($res)) { - $trailers = unserialize($res); + $trailers = unserialize($res, 'ade'); $ret .=""; $ret .= ""; $ret .= ""; - return ($ret); + return $ret; } } - if ($whichclass === "pop") { + if ($whichclass === 'pop') { if (!empty($res)) { - $trailers = unserialize($res); + $trailers = unserialize($res, 'pop'); $ret .= "";