diff --git a/lib/Film.php b/lib/Film.php index 71341117e..51553b5fe 100644 --- a/lib/Film.php +++ b/lib/Film.php @@ -10,7 +10,6 @@ require_once(WWW_DIR."/lib/rottentomato.php"); require_once(WWW_DIR."/lib/Tmux.php"); require_once("ColorCLI.php"); require_once("TraktTv.php"); -require_once("functions.php"); /** * Class Film @@ -118,7 +117,7 @@ class Film { $this->c = new ColorCLI(); $this->db = new DB(); - $this->functions = new Functions(); + $this->util = new Utility(); $t = new Tmux(); $this->tmux = $t->get(); $this->releaseImage = new ReleaseImage(); @@ -757,7 +756,7 @@ class Film protected function fetchFanartTVProperties($imdbId) { if ($this->fanartapikey != '') { - $buffer = $this->functions->getURL('http://api.fanart.tv/webservice/movie/' . $this->fanartapikey . '/tt' . $imdbId . '/xml/'); + $buffer = $this->util->getURL('http://api.fanart.tv/webservice/movie/' . $this->fanartapikey . '/tt' . $imdbId . '/xml/'); if ($buffer !== false) { $art = @simplexml_load_string($buffer); if ($art !== false) { @@ -892,8 +891,8 @@ class Film $buffer = - $this->functions->getURL( - 'http://' . ($this->imdburl === false ? 'www' : 'akas') . '.imdb.com/title/tt' . $imdbId . '/', + $this->util->getURL( + 'http://' . ($this->imdburl === false ? 'www' : 'akas') . '.imdb.com/title/tt' . $imdbId . '/', 'get', '', (!empty($this->imdblanguage) ? $this->imdblanguage : 'en'), @@ -1064,8 +1063,8 @@ class Film // Check OMDB api. $buffer = - $this->functions->getURL( - 'http://www.omdbapi.com/?t=' . + $this->util->getURL( + 'http://www.omdbapi.com/?t=' . urlencode($this->currentTitle) . ($this->currentYear !== false ? ('&y=' . $this->currentYear) : '') . '&r=json' @@ -1127,7 +1126,8 @@ class Film $andYearIn .= $end . ')'; } $IMDBCheck = $this->db->queryOneRow( - sprintf('%s WHERE title %s %s', $query, $this->functions->likeString($this->currentTitle), $andYearIn)); + sprintf('%s WHERE title %s %s', $query, $this->db->likeString($this->currentTitle), $andYearIn) + ); // Look by %word%word%word% etc.. if ($IMDBCheck === false) { @@ -1138,7 +1138,7 @@ class Film } $IMDBCheck = $this->db->queryOneRow( sprintf("%s WHERE replace(replace(title, \"'\", ''), '!', '') %s %s", - $query, $this->functions->likeString($tempTitle), $andYearIn + $query, $this->db->likeString($tempTitle), $andYearIn ) ); } @@ -1149,7 +1149,7 @@ class Film if ($tempTitle !== $this->currentTitle) { $IMDBCheck = $this->db->queryOneRow( sprintf('%s WHERE title %s %s', - $query, $this->functions->likeString($tempTitle), $andYearIn + $query, $this->db->likeString($tempTitle), $andYearIn ) ); @@ -1162,7 +1162,7 @@ class Film } $IMDBCheck = $this->db->queryOneRow( sprintf("%s WHERE replace(replace(replace(title, \"'\", ''), '!', ''), '\"', '') %s %s", - $query, $this->functions->likeString($tempTitle), $andYearIn + $query, $this->db->likeString($tempTitle), $andYearIn ) ); } @@ -1216,8 +1216,8 @@ class Film */ protected function googleSearch() { - $buffer = $this->functions->getURL( - 'https://www.google.com/search?hl=en&as_q=&as_epq=' . + $buffer = $this->util->getURL( + 'https://www.google.com/search?hl=en&as_q=&as_epq=' . urlencode( $this->currentTitle . ' ' . @@ -1250,8 +1250,8 @@ class Film */ protected function bingSearch() { - $buffer = $this->functions->getURL( - "http://www.bing.com/search?q=" . + $buffer = $this->util->getURL( + "http://www.bing.com/search?q=" . urlencode( '("' . $this->currentTitle . @@ -1279,8 +1279,8 @@ class Film */ protected function yahooSearch() { - $buffer = $this->functions->getURL( - "http://search.yahoo.com/search?n=10&ei=UTF-8&va_vt=title&vo_vt=any&ve_vt=any&vp_vt=any&vf=all&vm=p&fl=0&fr=fp-top&p=intitle:" . + $buffer = $this->util->getURL( + "http://search.yahoo.com/search?n=10&ei=UTF-8&va_vt=title&vo_vt=any&ve_vt=any&vp_vt=any&vf=all&vm=p&fl=0&fr=fp-top&p=intitle:" . urlencode( 'intitle:' . implode(' intitle:', diff --git a/lib/IRCScraper.php b/lib/IRCScraper.php index 1f7493094..e3671ee4b 100644 --- a/lib/IRCScraper.php +++ b/lib/IRCScraper.php @@ -3,7 +3,6 @@ require_once(dirname(__FILE__) . "/../bin/config.php"); require_once(WWW_DIR . "/lib/framework/db.php"); require_once("prehash.php"); require_once("IRCClient.php"); -require_once("functions.php"); /** @@ -119,7 +118,6 @@ class IRCScraper extends IRCClient } $this->db = new DB(); - $this->functions = new Functions(); $this->groupList = array(); $this->silent = $silent; $this->_debug = $debug; @@ -199,7 +197,7 @@ class IRCScraper extends IRCClient return; } - $this->CurPre['predate'] = $this->functions->from_unixtime(strtotime($matches['time'] . ' UTC')); + $this->CurPre['predate'] = $this->db->from_unixtime(strtotime($matches['time'] . ' UTC')); $this->CurPre['title'] = $matches['title']; $this->CurPre['source'] = $matches['source']; if ($matches['category'] !== 'N/A') { diff --git a/lib/Info.php b/lib/Info.php index f65c77483..fc16c62d6 100644 --- a/lib/Info.php +++ b/lib/Info.php @@ -1,15 +1,15 @@ echo = $echo; $s = new Sites(); $this->c = new ColorCLI(); @@ -104,22 +115,25 @@ class Info if (!preg_match('/[\/\\\\]$/', $this->tmpPath)) { $this->tmpPath .= '/'; } - $this->functions = new Functions(); + $this->util = new Utility(); } /** * Look for a TvRage ID in a string. * - * @param string $str The string with a TvRage ID. + * @param string $str The string with a TvRage ID. + * * @return string The TVRage ID on success. * @return bool False on failure. * * @access public */ - public function parseRageId($str) { + public function parseRageId($str) + { if (preg_match('/tvrage\.com\/shows\/id-(\d{1,6})/i', $str, $matches)) { return trim($matches[1]); } + return false; } @@ -128,6 +142,7 @@ class Info * * @param string $possibleNFO The nfo. * @param string $guid The guid of the release. + * * @return bool True on success, False on failure. * * @access public @@ -152,7 +167,7 @@ class Info file_put_contents($tmpPath, $possibleNFO); // Linux boxes have 'file' (so should Macs) - if ($this->functions->hasCommand('file')) { + if ($this->util->hasCommand('file')) { exec('file -b "' . $tmpPath . '"', $result); if (is_array($result)) { if (count($result) > 1) { @@ -178,7 +193,7 @@ class Info } // If above checks couldn't make a categorical identification, Use GetId3 to check if it's an image/video/rar/zip etc.. - require_once ("getid3/getid3/getid3.php"); + require_once("getid3/getid3/getid3.php"); $getid3 = new getid3(); $check = $getid3->analyze($tmpPath); @unlink($tmpPath); @@ -243,8 +258,10 @@ class Info ); $nzbContents->parseNZB($release['guid'], $release['ID'], $release['groupID']); } + return true; } + return false; } @@ -252,15 +269,16 @@ class Info * Attempt to find NFO files inside the NZB's of releases. * * @param string $releaseToWork - * @param int $processImdb Attempt to find IMDB id's in the NZB? - * @param int $processTvrage Attempt to find TvRage id's in the NZB? - * @param string $groupID (optional) The group ID to work on. - * @param object $nntp Instance of class NNTP. + * @param int $processImdb Attempt to find IMDB id's in the NZB? + * @param int $processTvrage Attempt to find TvRage id's in the NZB? + * @param string $groupID (optional) The group ID to work on. + * @param object $nntp Instance of class NNTP. * * @return int How many NFO's were processed? * */ - public function processNfoFiles($releaseToWork = '', $processImdb = 1, $processTvrage = 1, $groupID = '', $nntp) { + public function processNfoFiles($releaseToWork = '', $processImdb = 1, $processTvrage = 1, $groupID = '', $nntp) + { if (!isset($nntp)) { exit($this->c->error("Unable to connect to usenet.\n")); } @@ -309,7 +327,7 @@ class Info // Get count of releases per nfo status $outString = 'Available to process'; for ($i = -1; $i >= -6; $i--) { - $ns = $this->db->query('SELECT COUNT(*) AS count FROM releases WHERE nfostatus = ' . $i); + $ns = $this->db->query('SELECT COUNT(*) AS count FROM releases WHERE nfostatus = ' . $i); $outString .= ', ' . $i . ' = ' . number_format($ns[0]['count']); } $this->c->doEcho($this->c->header($outString . '.')); @@ -377,6 +395,7 @@ class Info } } } + return $ret; } diff --git a/lib/NZBGet.php b/lib/NZBGet.php index 3c8675c5a..cb5010e56 100644 --- a/lib/NZBGet.php +++ b/lib/NZBGet.php @@ -2,8 +2,8 @@ require_once(dirname(__FILE__) . "/../bin/config.php"); require_once(WWW_DIR . "/lib/framework/db.php"); require_once(WWW_DIR . "/lib/releases.php"); +require_once(WWW_DIR . "/lib/util.php"); require_once("Enzebe.php"); -require_once("functions.php"); /** * Class NZBGet * @@ -97,7 +97,7 @@ class NZBGet $this->fullURL = $this->verifyURL($this->url); $this->Releases = new Releases(); $this->NZB = new Enzebe(); - $this->functions = new Functions(); + $this->util = new Utility(); } /** @@ -149,7 +149,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'append', 'post', $header); + $this->util->getUrl($this->fullURL . 'append', 'post', $header); } /** @@ -198,7 +198,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'appendurl', 'post', $header); + $this->util->getUrl($this->fullURL . 'appendurl', 'post', $header); } /** @@ -220,7 +220,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'pausedownload2', 'post', $header); + $this->util->getUrl($this->fullURL . 'pausedownload2', 'post', $header); } /** @@ -242,7 +242,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'resumedownload2', 'post', $header); + $this->util->getUrl($this->fullURL . 'resumedownload2', 'post', $header); } /** @@ -277,7 +277,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'editqueue', 'post', $header); + $this->util->getUrl($this->fullURL . 'editqueue', 'post', $header); } /** @@ -312,7 +312,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'editqueue', 'post', $header); + $this->util->getUrl($this->fullURL . 'editqueue', 'post', $header); } /** @@ -347,7 +347,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'editqueue', 'post', $header); + $this->util->getUrl($this->fullURL . 'editqueue', 'post', $header); } /** @@ -371,7 +371,7 @@ class NZBGet '; - $this->functions->getUrl($this->fullURL . 'rate', 'post', $header); + $this->util->getUrl($this->fullURL . 'rate', 'post', $header); } /** @@ -383,7 +383,7 @@ class NZBGet */ public function getQueue() { - $data = $this->functions->getUrl($this->fullURL . 'listgroups'); + $data = $this->util->getUrl($this->fullURL . 'listgroups'); $retVal = false; if ($data) { $xml = simplexml_load_string($data); @@ -414,7 +414,7 @@ class NZBGet */ public function status() { - $data = $this->functions->getUrl($this->fullURL . 'status'); + $data = $this->util->getUrl($this->fullURL . 'status'); $retVal = false; if ($data) { $xml = simplexml_load_string($data); diff --git a/lib/Pprocess.php b/lib/Pprocess.php index 68c6495f9..ff4bc9258 100644 --- a/lib/Pprocess.php +++ b/lib/Pprocess.php @@ -29,7 +29,6 @@ require_once("TraktTv.php"); require_once("Film.php"); require_once("TvAnger.php"); require_once("Konsole.php"); -require_once("functions.php"); require_once("ProcessAdditional.php"); /** @@ -106,7 +105,6 @@ class PProcess $this->namefixer = new NameFixer($this->echooutput); $this->Nfo = new Info($this->echooutput); $this->releaseFiles = new ReleaseFiles(); - $this->functions = new Functions(true); //\\ Site object. $this->tmux = $t->get(); diff --git a/lib/ProcessAdditional.php b/lib/ProcessAdditional.php index 855750891..c6eb11019 100644 --- a/lib/ProcessAdditional.php +++ b/lib/ProcessAdditional.php @@ -18,6 +18,7 @@ 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/nzb.php"); +require_once(WWW_DIR . "/lib/util.php"); require_once("consoletools.php"); require_once("ColorCLI.php"); require_once("nzbcontents.php"); @@ -29,7 +30,6 @@ require_once("TraktTv.php"); require_once("Film.php"); require_once("TvAnger.php"); require_once("Konsole.php"); -require_once("functions.php"); require_once("Enzebe.php"); Class ProcessAdditional @@ -121,7 +121,7 @@ Class ProcessAdditional $this->_releaseImage = new ReleaseImage(); $this->_par2Info = new Par2Info(); $this->_nfo = new Info($this->_echoCLI); - $this->_functions = new Functions(); + $this->_util = new Utility(); $this->c = new ColorCLI(); $this->jpgSavePath = WWW_DIR . 'covers/sample/'; $this->vidSavePath = WWW_DIR . 'covers/video/'; @@ -137,7 +137,7 @@ Class ProcessAdditional } $this->_archiveInfo->setExternalClients($clients); - $this->_hasGNUFile = $this->_functions->hasCommand(('file') === true ? true : false); + $this->_hasGNUFile = $this->_util->hasCommand(('file') === true ? true : false); // Maximum amount of releases to fetch per run. $this->_queryLimit = @@ -228,7 +228,7 @@ Class ProcessAdditional 'name' => $release[2], 'disablepreview' => $release[3], 'size' => $release[4], - 'groupID' => $release[5], + 'groupID' => $release[5], 'nfostatus' => $release[6], 'categoryID' => $release[7], 'searchname' => $release[8] @@ -398,7 +398,7 @@ Class ProcessAdditional /** * Deletes files and folders recursively. * - * @param string $path Path to a folder or file. + * @param string $path Path to a folder or file. * @param array $ignoredFolders Array with paths to folders to ignore. * * @void @@ -1304,7 +1304,7 @@ Class ProcessAdditional * Optional, pass a regex to filter the files. * * @param string $pattern Regex, optional - * @param string $path Path to the folder (if empty, uses $this->tmpPath) + * @param string $path Path to the folder (if empty, uses $this->tmpPath) * * @return Iterator Object|bool */ diff --git a/lib/ReleaseRemover.php b/lib/ReleaseRemover.php index b42b3b694..90483e25f 100644 --- a/lib/ReleaseRemover.php +++ b/lib/ReleaseRemover.php @@ -1,13 +1,12 @@ color = new ColorCLI(); $this->consoleTools = new ConsoleTools(); $this->releases = new Releases(); - $this->functions = new Functions(); $this->nzb = new Enzebe(); $this->releaseImage = new ReleaseImage(); diff --git a/lib/Sharing.php b/lib/Sharing.php index 87ffebdab..0a998c8e2 100644 --- a/lib/Sharing.php +++ b/lib/Sharing.php @@ -110,7 +110,6 @@ Class Sharing $this->siteSettings['enabled'] = ($this->siteSettings['enabled'] == 1 ? true : false); $this->siteSettings['start_position'] = ($this->siteSettings['start_position'] == 1 ? true : false); //add functions.php - $this->functions = new Functions(); } /** @@ -174,7 +173,7 @@ Class Sharing INNER JOIN users u ON rc.userID = u.ID INNER JOIN releases r on rc.releaseID = r.ID WHERE rc.shared = 0 LIMIT %d', - $this->functions->unix_timestamp_column('rc.createddate'), + $this->db->unix_timestamp_column('rc.createddate'), $this->siteSettings['max_push'] ) ); @@ -493,7 +492,7 @@ Class Sharing (text, createddate, issynced, shareID, gid, nzb_guid, siteID, username, userID, releaseID, shared, host, sourceID) VALUES (%s, %s, 1, %s, %s, %s, %s, %s, 0, 0, 2, "", 999)', $this->db->escapeString($body['BODY']), - $this->functions->from_unixtime(($body['TIME'] > time() ? time() : $body['TIME'])), + $this->db->from_unixtime(($body['TIME'] > time() ? time() : $body['TIME'])), $this->db->escapeString($body['SID']), $this->db->escapeString($body['RID']), $this->db->escapeString($body['RID']), diff --git a/lib/TraktTv.php b/lib/TraktTv.php index 9687b2616..5b2b85659 100644 --- a/lib/TraktTv.php +++ b/lib/TraktTv.php @@ -1,7 +1,7 @@ get(); $this->APIKEY = $tmux->trakttvkey; - $this->functions = new Functions(); + $this->util = new Utility(); } /** @@ -34,8 +34,8 @@ Class TraktTv public function traktTVSEsummary($title = '', $season = '', $ep = '') { if (!empty($this->APIKEY)) { - $TVjson = $this->functions->getUrl( - 'http://api.trakt.tv/show/episode/summary.json/' . + $TVjson = $this->util->getUrl( + 'http://api.trakt.tv/show/episode/summary.json/' . $this->APIKEY . '/' . str_replace(array(' ', '_', '.'), '-', $title) . '/' . str_replace(array('S', 's'), '', $season) . '/' . @@ -62,8 +62,8 @@ Class TraktTv public function traktMoviesummary($movie = '', $array = false) { if (!empty($this->APIKEY)) { - $MovieJson = $this->functions->getUrl( - 'http://api.trakt.tv/movie/summary.json/' . + $MovieJson = $this->util->getUrl( + 'http://api.trakt.tv/movie/summary.json/' . $this->APIKEY . '/' . str_replace(array(' ', '_', '.'), '-', str_replace(array('(', ')'), '', $movie)) diff --git a/lib/copy_this/www/lib/framework/db.php b/lib/copy_this/www/lib/framework/db.php index 4200e8ccf..0ec5af59a 100644 --- a/lib/copy_this/www/lib/framework/db.php +++ b/lib/copy_this/www/lib/framework/db.php @@ -160,6 +160,45 @@ class DB ) ); } + + /** + * PHP interpretation of MySQL's from_unixtime method. + * + * @param int $utime UnixTime + * + * @return bool|string + */ + public function from_unixtime($utime) + { + return 'FROM_UNIXTIME(' . $utime . ')'; + } + + /** + * PHP interpretation of mysql's unix_timestamp method. + * + * @param string $date + * + * @return int + */ + public function unix_timestamp($date) + { + return strtotime($date); + } + + /** + * Get a string for MySQL with a column name in between + * ie: UNIX_TIMESTAMP(column_name) AS outputName + * + * @param string $column The datetime column. + * @param string $outputName The name to store the SQL data into. (the word after AS) + * + * @return string + */ + public function unix_timestamp_column($column, $outputName = 'unix_time') + { + return ('UNIX_TIMESTAMP(' . $column . ') AS ' . $outputName); + } + /** * Reconnect to MySQL when the connection has been lost. * diff --git a/lib/namefixer.php b/lib/namefixer.php index d065225d6..7e629bf47 100644 --- a/lib/namefixer.php +++ b/lib/namefixer.php @@ -25,6 +25,7 @@ class NameFixer /** * Has the current release found a new name? + * * @var bool */ public $matched; @@ -66,7 +67,6 @@ class NameFixer $this->c = new ColorCLI(); $this->consoletools = new ConsoleTools(); $this->category = new Categorize(); - $this->functions = new Functions(); $this->_groups = new Groups($this->db); $this->utility = new Utility(); } @@ -78,7 +78,7 @@ class NameFixer * @param int $echo 1: change the name, anything else: preview of what could have been changed. * @param int $cats 1: other categories, 2: all categories * @param $nameStatus - * @param $show + * @param $show */ public function fixNamesWithNfo($time, $echo, $cats, $nameStatus, $show) { @@ -130,7 +130,7 @@ class NameFixer // Ignore encrypted NFOs. if (preg_match('/^=newz\[NZB\]=\w+/', $releaseRow['textstring'])) { $this->db->queryExec( - sprintf('UPDATE releases SET proc_nfo = 1 WHERE ID = %d', $releaseRow['releaseID']) + sprintf('UPDATE releases SET proc_nfo = 1 WHERE ID = %d', $releaseRow['releaseID']) ); continue; } @@ -153,7 +153,7 @@ class NameFixer * @param int $echo 1: change the name, anything else: preview of what could have been changed. * @param int $cats 1: other categories, 2: all categories * @param $nameStatus - * @param $show + * @param $show */ public function fixNamesWithFiles($time, $echo, $cats, $nameStatus, $show) { @@ -207,11 +207,11 @@ class NameFixer /** * Attempts to fix release names using the Par2 File. * - * @param int $time 1: 24 hours, 2: no time limit - * @param int $echo 1: change the name, anything else: preview of what could have been changed. - * @param int $cats 1: other categories, 2: all categories - * @param $nameStatus - * @param $show + * @param int $time 1: 24 hours, 2: no time limit + * @param int $echo 1: change the name, anything else: preview of what could have been changed. + * @param int $cats 1: other categories, 2: all categories + * @param $nameStatus + * @param $show * @param NNTP $nntp */ public function fixNamesWithPar2($time, $echo, $cats, $nameStatus, $show, $nntp) @@ -286,6 +286,7 @@ class NameFixer echo $this->c->header($query . $this->fullall . ";\n"); $releases = $this->db->queryDirect($query . $this->fullall); } + return $releases; } @@ -575,6 +576,7 @@ class NameFixer } elseif ($total >= 16) { $matching = -1; } + return $matching; } @@ -761,6 +763,7 @@ class NameFixer ) ); } + return $matching; }