From e8c3f6018395e2d69e51a7fa6e413de1bcce9e10 Mon Sep 17 00:00:00 2001 From: Darko Date: Fri, 16 Aug 2013 11:52:11 +0200 Subject: [PATCH] Updates --- scripts/fix_files.sh | 8 +- test/files to copy/www/lib/category.php | 1451 ------------- test/files to copy/www/lib/framework/db.php | 242 --- test/files to copy/www/lib/groups.php | 291 --- test/files to copy/www/lib/nfo.php | 712 ------- test/files to copy/www/lib/releases.php | 2126 ------------------- test/fixReleaseNames.php | 1 + test/namecleaner.php | 1 + test/namefixer.php | 1 + test/prehash.php | 1 + test/removeCrapReleases.php | 1 + 11 files changed, 9 insertions(+), 4826 deletions(-) delete mode 100755 test/files to copy/www/lib/category.php delete mode 100755 test/files to copy/www/lib/framework/db.php delete mode 100755 test/files to copy/www/lib/groups.php delete mode 100755 test/files to copy/www/lib/nfo.php delete mode 100755 test/files to copy/www/lib/releases.php diff --git a/scripts/fix_files.sh b/scripts/fix_files.sh index e539c85ea..4730d7f8e 100755 --- a/scripts/fix_files.sh +++ b/scripts/fix_files.sh @@ -49,10 +49,10 @@ if [[ $KEVIN_SAFER == "true" ]] || [[ $PARSING_MOD == "true" ]]; then cp -frv * $NEWZPATH/www/lib/ fi #copy needed files for hash_decrypt and fixReleaseNames scripts -if [[ $HASH == "true" ]] || [[ $FIXRELEASES == "true" ]]; then - cd $DIR"/test/files to copy/www/lib" - cp -frv * $NEWZPATH/www/lib/ -fi +#if [[ $HASH == "true" ]] || [[ $FIXRELEASES == "true" ]]; then +# cd $DIR"/test/files to copy/www/lib" +# cp -frv * $NEWZPATH/www/lib/ +#fi #set user/group to www echo "Fixing permisions, this can take some time if you have a large set of releases" diff --git a/test/files to copy/www/lib/category.php b/test/files to copy/www/lib/category.php deleted file mode 100755 index cd6c8c664..000000000 --- a/test/files to copy/www/lib/category.php +++ /dev/null @@ -1,1451 +0,0 @@ - 0) - $exccatlist = " and c.ID not in (".implode(",", $excludedcats).")"; - - $act = ""; - if ($activeonly) - $act = sprintf(" where c.status = %d ", Category::STATUS_ACTIVE) ; - - if ($exccatlist != "") - $act.=$exccatlist; - - return $db->query("select c.ID, concat(cp.title, ' > ',c.title) as title, cp.ID as parentID, c.status from category c inner join category cp on cp.ID = c.parentID ".$act." ORDER BY c.ID", true); - } - - /** - * Determine if a category is a parent. - */ - public function isParent($cid) - { - $db = new DB(); - $ret = $db->queryOneRow(sprintf("select count(*) as count from category where ID = %d and parentID is null", $cid), true); - if ($ret['count']) - return true; - else - return false; - } - - /** - * Get a list of categories and their parents. - */ - public function getFlat($activeonly=false) - { - $db = new DB(); - $act = ""; - if ($activeonly) - $act = sprintf(" where c.status = %d ", Category::STATUS_ACTIVE ) ; - return $db->query("select c.*, (SELECT title FROM category WHERE ID=c.parentID) AS parentName from category c ".$act." ORDER BY c.ID"); - } - - /** - * Get a list of all child categories for a parent. - */ - public function getChildren($cid) - { - $db = new DB(); - return $db->query(sprintf("select c.* from category c where parentID = %d", $cid), true); - } - - /** - * Get a category row by its ID. - */ - public function getById($id) - { - $db = new DB(); - return $db->queryOneRow(sprintf("SELECT c.disablepreview, c.ID, c.description, c.minsizetoformrelease, c.maxsizetoformrelease, CONCAT(COALESCE(cp.title,'') , CASE WHEN cp.title IS NULL THEN '' ELSE ' > ' END , c.title) as title, c.status, c.parentID from category c left outer join category cp on cp.ID = c.parentID where c.ID = %d", $id)); - } - - /* - * Return min/max size range (in array(min, max)) otherwise, none is returned - * if no size restrictions are set - */ - public function getSizeRangeById($id) - { - $db = new DB(); - $res = $db->queryOneRow(sprintf("SELECT c.minsizetoformrelease, c.maxsizetoformrelease, cp.minsizetoformrelease as p_minsizetoformrelease, cp.maxsizetoformrelease as p_maxsizetoformrelease". - " from category c left outer join category cp on cp.ID = c.parentID where c.ID = %d", $id)); - if(!$res) - return null; - - $min = intval($res['minsizetoformrelease']); - $max = intval($res['maxsizetoformrelease']); - if($min == 0 && $max == 0){ - # Size restriction disabled; now check parent - $min = intval($res['p_minsizetoformrelease']); - $max = intval($res['p_maxsizetoformrelease']); - if($min == 0 && $max == 0){ - # no size restriction - return null; - } - else if($max > 0) - { - $min = 0; - $max = intval($res['p_maxsizetoformrelease']); - } - else - { - $min = intval($res['p_minsizetoformrelease']); - $max = PHP_INT_MAX; - } - } - else if($max > 0) - { - $min = 0; - $max = intval($res['maxsizetoformrelease']); - } - else - { - $min = intval($res['minsizetoformrelease']); - $max = PHP_INT_MAX; - } - - # If code reaches here, then content is enabled - return array('min'=>$min, 'max'=>$max); - } - - /** - * Get a list of categories by an array of IDs. - */ - public function getByIds($ids) - { - $db = new DB(); - return $db->query(sprintf("SELECT concat(cp.title, ' > ',c.title) as title from category c inner join category cp on cp.ID = c.parentID where c.ID in (%s)", implode(',', $ids))); - } - - //**Added from nZEDb - public function getNameByID($ID) - { - $db = new DB(); - $arr1 = $db->queryOneRow(sprintf("SELECT title from category where ID = %d", substr($ID, 0, 1)."000")); - $parent = array_shift($arr1); - $arr2 = $db->queryOneRow(sprintf("SELECT title from category where ID = %d", $ID)); - $cat = array_shift($arr2); - return $parent." ".$cat; - } - //End of addition - - /** - * Update a category. - */ - public function update($id, $status, $desc, $disablepreview, $minsize, $maxsize) - { - $db = new DB(); - return $db->query(sprintf("update category set disablepreview = %d, status = %d, minsizetoformrelease = %d, maxsizetoformrelease = %d, description = %s where ID = %d", $disablepreview, $status, $minsize, $maxsize, $db->escapeString($desc), $id)); - } - - /** - * Get the categories in a format for use by the headermenu.tpl. - */ - public function getForMenu($excludedcats=array()) - { - $db = new DB(); - $ret = array(); - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and ID not in (".implode(",", $excludedcats).")"; - - $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; - - foreach ($ret as $key => $parent) - { - $subcatlist = array(); - $subcatnames = array(); - foreach ($arr as $a) - { - if ($a["parentID"] == $parent["ID"]) - { - $subcatlist[] = $a; - $subcatnames[] = $a["title"]; - } - } - - if (count($subcatlist) > 0) - { - array_multisort($subcatnames, SORT_ASC, $subcatlist); - $ret[$key]["subcatlist"] = $subcatlist; - } - else - { - unset($ret[$key]); - } - } - return $ret; - } - - /** - * Return a list of categories for use in a dropdown. - */ - public function getForSelect($blnIncludeNoneSelected = true) - { - $categories = $this->get(); - $temp_array = array(); - - if ($blnIncludeNoneSelected) - { - $temp_array[-1] = "--Please Select--"; - } - - foreach($categories as $category) - $temp_array[$category["ID"]] = $category["title"]; - - return $temp_array; - } - - /** - * Work out which category is applicable for either a group or a binary. - * Returns -1 if no category is appropriate from the group name. - */ - function determineCategory($group, $releasename = "") - { - // - // Try and determine based on group - First Pass - // - - if (preg_match('/alt\.binaries\.0day/i', $group)) - { - if($this->isPC($releasename)){ return $this->tmpCat; } - return Category::CAT_PC_0DAY; - } - - if (preg_match('/alt\.binaries\.ath/i', $group)) - { - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.b4e/', $group)) - { - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isBook($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\..*?audiobook.*?/i', $group)) - return Category::CAT_MUSIC_AUDIOBOOK; - - if (preg_match('/lossless|flac/i', $group)) - { - return Category::CAT_MUSIC_LOSSLESS; - } - - if (preg_match('/alt\.binaries\.sounds.*?|alt\.binaries\.mp3.*?|alt\.binaries.*?\.mp3/i', $group)) - { - if($this->isMusic($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.console.ps3/i', $group)) - { - if($this->isConsole($releasename)){ return $this->tmpCat; } - return Category::CAT_GAME_PS3; - } - - if (preg_match('/alt\.binaries\.games\.xbox*/i', $group)) - { - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.games$/i', $group)) - { - if($this->isConsole($releasename)){ return $this->tmpCat; } - return Category::CAT_PC_GAMES; - } - - if (preg_match('/alt\.binaries\.games\.wii/i', $group)) - { - if($this->isConsole($releasename)) { return $this->tmpCat; } - } - if (preg_match('/alt\.binaries\.dvd.*?/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTv($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - if (preg_match('/alt\.binaries\.hdtv*|alt\.binaries\.x264|alt\.binaries\.tv$/i', $group)) - { - if($this->isMusicVideo($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isTv($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - if (preg_match('/alt\.binaries\.nospam\.cheerleaders/i', $group)) - { - if($this->isMusicVideo($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isTv($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.classic\.tv.*?/i', $group)) - { - if($this->isTv($releasename)){ return $this->tmpCat; } - return Category::CAT_TV_OTHER; - } - - if (preg_match('/alt\.binaries\.multimedia\.anime(\.highspeed)?/i', $group)) - { - return Category::CAT_TV_ANIME; - } - - if (preg_match('/alt\.binaries\.anime/i', $group)) - { - return Category::CAT_TV_ANIME; - } - - if (preg_match('/alt\.binaries\.e(-|)book*?/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - return Category::CAT_BOOK_EBOOK; - } - - if (preg_match('/alt\.binaries\.comics.*?/i', $group)) - { - return Category::CAT_BOOK_COMICS; - } - - if (preg_match('/alt\.binaries\.cores.*?/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.lou/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.cd.image|alt\.binaries\.audio\.warez/i', $group)) - { - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - return Category::CAT_PC_0DAY; - } - - if (preg_match('/alt\.binaries\.pro\-wrestling/i', $group)) - { - return Category::CAT_TV_SPORT; - } - - if (preg_match('/alt\.binaries\.sony\.psp/i', $group)) - { - return Category::CAT_GAME_PSP; - } - - if (preg_match('/alt\.binaries\.nintendo\.ds|alt\.binaries\.games\.nintendods/i', $group)) - { - return Category::CAT_GAME_NDS; - } - - if (preg_match('/alt\.binaries\.mpeg\.video\.music/i', $group)) - { - return Category::CAT_MUSIC_VIDEO; - } - - if (preg_match('/alt\.binaries\.mac/i', $group)) - { - return Category::CAT_PC_MAC; - } - - if (preg_match('/linux/i', $group)) - { - return Category::CAT_PC_ISO; - } - - if (preg_match('/alt\.binaries\.illuminaten/i', $group)) - { - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.ipod\.videos\.tvshows/i', $group)) - { - return Category::CAT_TV_OTHER; - } - - if (preg_match('/alt\.binaries\.documentaries/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isDocuTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.drummers/i', $group)) - { - if($this->isBookEbook($releasename)){ return $this->tmpCat; } - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.tv\.swedish/i', $group)) - { - if($this->isForeignTV($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.tv\.deutsch/i', $group)) - { - if($this->isForeignTV($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.erotica\.divx/i', $group)) - { - if($this->isXXX($releasename)){ return $this->tmpCat; } - return Category::CAT_XXX_OTHER; - } - - if (preg_match('/alt\.binaries\.ghosts/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.mom/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.mma|alt\.binaries\.multimedia\.sports.*?/i', $group)) - { - return Category::CAT_TV_SPORT; - } - - if (preg_match('/alt\.binaries\.b4e$/i', $group)) - { - if($this->isPC($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.warez\.smartphone/i', $group)) - { - if($this->isPC($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.warez\.ibm\-pc\.0\-day|alt\.binaries\.warez/i', $group)) - { - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_PC_0DAY; - } - - if (preg_match('/erotica|ijsklontje|kleverig/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - return Category::CAT_XXX_OTHER; - } - - if (preg_match('/french/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - return Category::CAT_MOVIE_FOREIGN; - } - - if (preg_match('/alt\.binaries\.movies\.xvid|alt\.binaries\.movies\.divx|alt\.binaries\.movies/i', $group)) - { - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/wmvhd/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/inner\-sanctum/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.worms/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMusicVideo($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - } - - if (preg_match('/alt\.binaries\.x264/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MOVIE_OTHER; - } - - if (preg_match('/dk\.binaer\.ebooks/i', $group)) - { - if($this->isBookEbook($releasename)){ return $this->tmpCat; } - return Category::CAT_BOOK_EBOOK; - } - - if (preg_match('/dk\.binaer\.film/i', $group)) - { - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/dk\.binaer\.musik/i', $group)) - { - if($this->isMusic($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - if (preg_match('/alt\.binaries\.(teevee|multimedia|tv|tvseries).*?/i', $group)) - { - if($this->isXxx($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - // - // if a category hasnt been set yet, then try against all - // functions and if still nothing, return Cat Misc. - // - if($this->isXXX($releasename)){ return $this->tmpCat; } - if($this->isBook($releasename)){ return $this->tmpCat; } - if($this->isPC($releasename)){ return $this->tmpCat; } - if($this->isConsole($releasename)){ return $this->tmpCat; } - if($this->isMusic($releasename)){ return $this->tmpCat; } - if($this->isTV($releasename)){ return $this->tmpCat; } - if($this->isMovie($releasename)){ return $this->tmpCat; } - return Category::CAT_MISC_OTHER; - } - - // - // Beginning of functions to determine category by release name - // - - /** - * Work out if a release is Hashed/Encrypted/Etc - */ - - public function isHashed($releasename) - { - if(!preg_match('/( |\.|\-)/i', $releasename) && preg_match('/^[a-z0-9]+$/i', $releasename)) - { - $this->tmpCat = Category::CAT_MISC_OTHER; - return true; - } - } - /** - * Work out if a release is TV - */ - public function isTV($releasename) - { - //echo "tv"; - if($this->isHashed($releasename)){ return true; } - if(preg_match('/(S?(\d{1,2})\.?(E|X|D)(\d{1,2})[\. _-]+)|(dsr|pdtv|hdtv)[\.\-_]/i', $releasename)) - { - //echo "tv1"; - if($this->isForeignTV($releasename)){ return true; } - if($this->isSportTV($releasename)){ return true; } - if($this->isDocuTV($releasename)){ return true; } - if($this->isHDTV($releasename)){ return true; } - if($this->isSDTV($releasename)){ return true; } - $this->tmpCat = Category::CAT_TV_OTHER; - return true; - } - else if (preg_match('/( S\d{1,2} |\.S\d{2}\.|\.S\d{2}|s\d{1,2}e\d{1,2}|(\.| |\b|\-)EP\d{1,2}\.|\.E\d{1,2}\.|special.*?HDTV|HDTV.*?special|PDTV|\.\d{3}\.DVDrip|History( |\.|\-)Channel|trollhd|trollsd|HDTV.*?BTL|C4TV|WEB DL|web\.dl|WWE|season \d{1,2}|(?!collectors).*?series|\.TV\.|\.dtv\.|UFC|TNA|staffel|episode|special\.\d{4})/i', $releasename)) - { - //echo "tv2"; - if($this->isForeignTV($releasename)){ return true; } - if($this->isSportTV($releasename)){ return true; } - if($this->isDocuTV($releasename)){ return true; } - if($this->isHDTV($releasename)){ return true; } - if($this->isSDTV($releasename)){ return true; } - $this->tmpCat = Category::CAT_TV_OTHER; - return true; - } - else if (preg_match('/seizoen/i', $releasename)) - { - if($this->isForeignTV($releasename)){ return true; } - } - return false; - } - - /** - * Work out if a release is Foreign TV - */ - public function isForeignTV($releasename) - { - - if(preg_match('/(seizoen|staffel|danish|flemish|(\.| |\b|\-)(HU|NZ)|dutch|Deutsch|nl\.?subbed|nl\.?sub|\.NL|\.ITA|norwegian|swedish|swesub|french|german|spanish)[\.\- \b]/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_FOREIGN; - return true; - } - else if(preg_match('/\.des\.(?!moines)|Chinese\.Subbed|vostfr|Hebrew\.Dubbed|\.HEB\.|Nordic|Hebdub|NLSubs|NL\-Subs|NLSub|Deutsch| der |German | NL |staffel|videomann/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_FOREIGN; - return true; - } - else if(preg_match('/(danish|flemish|nlvlaams|dutch|nl\.?sub|swedish|swesub|icelandic|finnish|french|truefrench[\.\- ](?:.dtv|dvd|br|bluray|720p|1080p|LD|dvdrip|internal|r5|bdrip|sub|cd\d|dts|dvdr)|german|nl\.?subbed|deutsch|espanol|SLOSiNH|VOSTFR|norwegian|[\.\- ]pl|pldub|norsub|[\.\- ]ITA)[\.\- ]/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_FOREIGN; - return true; - } - else if(preg_match('/(french|german)$/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_FOREIGN; - return true; - } - return false; - } - /** - * Work out if a release is Sport TV - */ - public function isSportTV($releasename) - { - if(preg_match('/(f1\.legends|epl|motogp|bellator|strikeforce|the\.ultimate\.fighter|supercup|wtcc|red\.bull.*?race|tour\.de\.france|bundesliga|la\.liga|uefa|EPL|ESPN|WWE\.|WWF\.|WCW\.|MMA\.|UFC\.|(^|[\. ])FIA\.|PGA\.|NFL\.|NCAA\.)/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - else if(preg_match('/Twenty20|IIHF|wimbledon|Kentucky\.Derby|WBA|Rugby\.|TNA\.|DTM\.|NASCAR|SBK|NBA(\.| )|NHL\.|NRL\.|MLB\.|Playoffs|FIFA\.|Serie.A|netball\.anz|formula1|indycar|Superleague|V8\.Supercars|((19|20)\d{2}.*?olympics?|olympics?.*?(19|20)\d{2})|x(\ |\.|\-)games/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - else if(preg_match('/(\b|\_|\.| )(Daegu|AFL|La.Vuelta|BMX|Gymnastics|IIHF|NBL|FINA|Drag.Boat|HDNET.Fights|Horse.Racing|WWF|World.Championships|Tor.De.France|Le.Triomphe|Legends.Of.Wrestling)(\b|\_|\.| )/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - else if(preg_match('/(\b|\_|\.| )(Fighting.Championship|tour.de.france|Boxing|Cycling|world.series|Formula.Renault|FA.Cup|WRC|GP3|WCW|Road.Racing|AMA|MFC|Grand.Prix|Basketball|MLS|Wrestling|World.Cup)(\b|\_|\.| )/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - else if(preg_match('/(\b|\_|\.| )(Swimming.*?Men|Swimming.*?Women|swimming.*?champion|WEC|World.GP|CFB|Rally.Challenge|Golf|Supercross|WCK|Darts|SPL|Snooker|League Cup|Ligue1|Ligue)(\b|\_|\.| )/i', $releasename)) - { - - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - else if(preg_match('/(\b|\_|\.| )(Copa.del.rey|League.Cup|Carling.Cup|Cricket|The.Championship|World.Max|KNVB|GP2|Soccer|PGR3|Cage.Contender|US.Open|CFL|Weightlifting|New.Delhi|Euro|WBC)(\b|\_|\.| )/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - else if(preg_match('/^london(\.| )2012/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SPORT; - return true; - } - - return false; - } - - /** - * Work out if a release is Documentary TV - */ - public function isDocuTV($releasename) - { - if (preg_match('/\-DOCUMENT/', $releasename)) //The DOCUMENT posting group does not actually do Documentary's - { - return false; - } - else if (preg_match('/(?!.*?S\d{2}.*?)(?!.*?EP?\d{2}.*?)(48\.Hours\.Mystery|Discovery.Channel|BBC|History.Channel|National.Geographic|Nat Geo|Shark.Week)/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_DOCU; - return true; - } - else if(preg_match('/(?!.*?S\d{2}.*?)(?!.*?EP?\d{2}.*?)((\b|_)(docu|BBC|document|a.and.e|National.geographic|Discovery.Channel|History.Channel|Travel.Channel|Science.Channel|Biography|Modern.Marvels|Inside.story|Hollywood.story|E.True|Documentary)(\b|_))/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_DOCU; - return true; - } - else if(preg_match('/(?!.*?S\d{2}.*?)(?!.*?EP?\d{2}.*?)((\b|_)(Science.Channel|National.geographi|History.Chanel|Colossal|Discovery.travel|Planet.Science|Animal.Planet|Discovery.Sci|Regents|Discovery.World|Discovery.truth|Discovery.body|Dispatches|Biography|The.Investigator|Private.Life|Footballs.Greatest|Most.Terrifying)(\b|_))/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_DOCU; - return true; - } - - return false; - } - - /** - * Work out if a release is HD TV - */ - public function isHDTV($releasename) - { - if (preg_match('/1080|720/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_HD; - return true; - } - - return false; - } - - /** - * Work out if a release is SD TV - */ - public function isSDTV($releasename) - { - if (preg_match('/(SDTV|HDTV|XVID|DIVX|PDTV|WEBDL|DVDR|DVD-RIP|WEB-DL|x264|dvd)/i', $releasename)) - { - $this->tmpCat = Category::CAT_TV_SD; - return true; - } - - return false; - } - - - /** - * Work out if a release is a Movie - */ - public function isMovie($releasename) - { - if($this->isHashed($releasename)){ return true; } - if($this->isMovieForeign($releasename)){ return true; } - if($this->isMovieSD($releasename)){ return true; } - if($this->isMovie3D($releasename)){ return true; } - if($this->isMovieHD($releasename)){ return true; } - //if($this->isMovieSD($releasename)){ return true; } - if($this->isMovieBluRay($releasename)){ return true; } - if (preg_match('/xvid/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_OTHER; - return true; - } - return false; - } - - /** - * Work out if a release is a Foreign Movie - */ - public function isMovieForeign($releasename) - { - if(preg_match('/(\.des\.|danish|flemish|dutch|(\.| |\b|\-)(HU|FINA)|Deutsch|nl\.?subbed|nl\.?sub|\.NL|\.ITA|norwegian|swedish|swesub|french|german|spanish)[\.\- |\b]/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_FOREIGN; - return true; - } - else if(preg_match('/Chinese\.Subbed|vostfr|Hebrew\.Dubbed|\.Heb\.|Hebdub|NLSubs|NL\-Subs|NLSub|Deutsch| der |German| NL |turkish/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_FOREIGN; - return true; - } - else if (preg_match('/(danish|flemish|nlvlaams|dutch|nl\.?sub|swedish|swesub|icelandic|finnish|french|truefrench[\.\- ](?:dvd|br|bluray|720p|1080p|LD|dvdrip|internal|r5|bdrip|sub|cd\d|dts|dvdr)|german|nl\.?subbed|deutsch|espanol|SLOSiNH|VOSTFR|norwegian|[\.\- ]pl|pldub|norsub|[\.\- ]ITA)[\.\- ]/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_FOREIGN; - return true; - } - return false; - } - - /** - * Work out if a release is a SD Movie - */ - public function isMovieSD($releasename) - { - if(preg_match('/(dvdscr|extrascene|dvdrip|\.CAM|dvdr|dvd9|dvd5|[\.\-\ ]ts)[\.\-\ ]/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_SD; - return true; - } - else if(preg_match('/(divx|xvid|(\.| )r5(\.| ))/i', $releasename) && !preg_match('/(720|1080)/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_SD; - return true; - } - return false; - } - - /** - * Work out if a release is a 3D Movie - */ - public function isMovie3D($releasename) - { - if(preg_match('/3D/i', $releasename) && preg_match('/[\-\. _](H?SBS|OU)([\-\. _]|$)/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_3D; - return true; - } - - return false; - } - - /** - * Work out if a release is a HD Movie - */ - public function isMovieHD($releasename) - { - if(preg_match('/x264|wmvhd|web\-dl|XvidHD|BRRIP|HDRIP|HDDVD|bddvd|BDRIP|webscr/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_HD; - return true; - } - - return false; - } - - /** - * Work out if a release is a Bluray Movie - */ - public function isMovieBluRay($releasename) - { - if(preg_match('/bluray|bd?25|bd?50|blu-ray|VC1|VC\-1|AVC|BDREMUX/i', $releasename)) - { - $this->tmpCat = Category::CAT_MOVIE_BLURAY; - return true; - } - - return false; - } - - /** - * Work out if a release is PC App - */ - public function isPC($releasename) - { - if($this->isHashed($releasename)){ return true; } - if($this->isMobileAndroid($releasename)){ return true; } - if($this->isMobileiOS($releasename)){ return true; } - if($this->isMobileOther($releasename)){ return true; } - if($this->isISO($releasename)){ return true; } - if($this->isMac($releasename)){ return true; } - if($this->isPCGame($releasename)){ return true; } - if($this->is0day($releasename)){ return true; } - return false; - } - - /** - * Work out if a release is Mobile Android App - */ - public function isMobileAndroid($releasename) - { - if (preg_match('/Android/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_MOBILEANDROID; - return true; - } - return false; - } - - /** - * Work out if a release is Mobile iOS App - */ - public function isMobileiOS($releasename) - { - if (preg_match('/(?!.*?Winall.*?)(IPHONE|ITOUCH|IPAD|Ipod)/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_MOBILEIOS; - return true; - } - return false; - } - - /** - * Work out if a release is Mobile Other App - */ - public function isMobileOther($releasename) - { - if (preg_match('/COREPDA|symbian|xscale|wm5|wm6|J2ME/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_MOBILEOTHER; - return true; - } - return false; - } - - /** - * Work out if a release is 0day App - */ - public function is0day($releasename) - { - if(preg_match('/DVDRIP|XVID.*?AC3|DIVX\-GERMAN/i', $releasename)) - { - return false; - } - - if(preg_match('/[\.\-_ ](x32|x64|x86|win64|winnt|win9x|win2k|winxp|winnt2k2003serv|win9xnt|win9xme|winnt2kxp|win2kxp|win2kxp2k3|keygen|regged|keymaker|winall|win32|template|Patch|GAMEGUiDE|unix|irix|solaris|freebsd|hpux|linux|windows|multilingual|software|Pro v\d{1,3})[\.\-_ ]/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_0DAY; - return true; - } - else if (preg_match('/(?!MDVDR).*?\-Walmart|PHP|\-SUNiSO|\.Portable\.|Adobe|CYGNUS|GERMAN\-|v\d{1,3}.*?Pro|MULTiLANGUAGE|Cracked|lz0|\-BEAN|MultiOS|\-iNViSiBLE|\-SPYRAL|WinAll|Keymaker|Keygen|Lynda\.com|FOSI|Keyfilemaker|DIGERATI|\-UNION|\-DOA|Laxity/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_0DAY; - return true; - } - return false; - } - - /** - * Work out if a release is Mac App - */ - public function isMac($releasename) - { - if(preg_match('/osx|os\.x|\.mac\.|MacOSX/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_MAC; - return true; - } - return false; - } - - /** - * Work out if a release is ISO App - */ - public function isISO($releasename) - { - if(preg_match('/\-DYNAMiCS/', $releasename)) - { - $this->tmpCat = Category::CAT_PC_ISO; - return true; - } - return false; - } - - /** - * Work out if a release is PC Game - */ - public function isPCGame($releasename) - { - if (preg_match('/\-Heist|\-RELOADED|\.GAME\-|\-SKIDROW|PC GAME|FASDOX|v\d{1,3}.*?\-TE|RIP\-unleashed|Razor1911/i', $releasename)) - { - $this->tmpCat = Category::CAT_PC_GAMES; - return true; - } - return false; - } - - - /** - * Work out if a release is XXX - */ - public function isXxx($releasename) - { - if($this->isHashed($releasename)){ return true; } - if(preg_match('/(\.JAV\.| JAV |\.Jav\.|Girls.*?Gone.*?Wild|\-MotTto|-Nukleotide|XXX|PORNOLATiON|SWE6RUS|swe6|SWE6|NYMPHO|DETOXATiON|DivXfacTory|TESORO|STARLETS|xxx|XxX|PORNORIP|PornoRip)/', $releasename)) - { - if($this->isXxxDVD($releasename)){ return true; } - if($this->isXxxImageset($releasename)){ return true; } - if($this->isXxxPack($releasename)){ return true; } - if($this->isXxxWMV($releasename)){ return true; } - if($this->isXxx264($releasename)){ return true; } - if($this->isXxxXvid($releasename)){ return true; } - $this->tmpCat = Category::CAT_XXX_XVID; - return true; - } - else if(preg_match('/^Penthouse/i', $releasename)) - { - if($this->isXxxDVD($releasename)){ return true; } - if($this->isXxxImageset($releasename)){ return true; } - if($this->isXxxPack($releasename)){ return true; } - if($this->isXxxWMV($releasename)){ return true; } - if($this->isXxx264($releasename)){ return true; } - if($this->isXxxXvid($releasename)){ return true; } - $this->tmpCat = Category::CAT_XXX_XVID; - return true; - } - - return false; - } - - /** - * Work out if a release is HD XXX - */ - public function isXxx264($releasename) - { - if (preg_match('/x264|720|1080/i', $releasename)) - { - $this->tmpCat = Category::CAT_XXX_X264; - return true; - } - return false; - } - - /** - * Work out if a release is SD XXX - */ - public function isXxxXvid($releasename) - { - if (preg_match('/xvid|dvdrip|bdrip|brrip|pornolation|swe6|nympho|detoxication|tesoro|mp4/i', $releasename)) - { - $this->tmpCat = Category::CAT_XXX_XVID; - return true; - } - - return false; - } - - /** - * Work out if a release is Other XXX - */ - public function isXxxWMV($releasename) - { - if (preg_match('/wmv|f4v|flv|mov(?!ie)|mpeg|isom|realmedia|multiformat/i', $releasename)) - { - $this->tmpCat = Category::CAT_XXX_WMV; - return true; - } - - return false; - } - - /** - * Work out if a release is XXX DVDR - */ - public function isXxxDVD($releasename) - { - if (preg_match('/dvdr[^ip]|dvd5|dvd9/i', $releasename)) - { - $this->tmpCat = Category::CAT_XXX_DVD; - return true; - } - - return false; - } - - /** - * Work out if a release is XXX Pack - */ - public function isXxxPack($releasename) - { - if (preg_match('/[\._](pack)[\.\-_]/i', $releasename)) - { - $this->tmpCat = Category::CAT_XXX_PACK; - return true; - } - return false; - } - - /** - * Work out if a release is XXX ImageSet - */ - public function isXxxImageset($releasename) - { - if (preg_match('/imageset/i', $releasename)) - { - $this->tmpCat = Category::CAT_XXX_IMAGESET; - return true; - } - return false; - } - - /** - * Work out if a release is Console App - */ - public function isConsole($releasename) - { - if($this->isHashed($releasename)){ return true; } - if($this->isGameNDS($releasename)){return true;} - if($this->isGamePS3($releasename)){ return true; } - if($this->isGamePSP($releasename)){ return true; } - if($this->isGameWiiWare($releasename)){ return true; } - if($this->isGameWii($releasename)){ return true; } - if($this->isGameXBOX360DLC($releasename)){ return true; } - if($this->isGameXBOX360($releasename)){ return true; } - if($this->isGameXBOX($releasename)){ return true; } - - return false; - } - - /** - * Work out if a release is NDS App - */ - public function isGameNDS($releasename) - { - if (preg_match('/(\b|\-| |\.)(3DS|NDS)(\b|\-| |\.)/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_NDS; - return true; - } - - return false; - } - - /** - * Work out if a release is PS3 App - */ - public function isGamePS3($releasename) - { - if (preg_match('/PS3\-/', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_PS3; - return true; - } - - return false; - } - - /** - * Work out if a release is PSP App - */ - public function isGamePSP($releasename) - { - if (preg_match('/PSP\-/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_PSP; - return true; - } - - return false; - } - - /** - * Work out if a release is WiiWare App - */ - public function isGameWiiWare($releasename) - { - if (preg_match('/WIIWARE|WII.*?VC|VC.*?WII|WII.*?DLC|DLC.*?WII|WII.*?CONSOLE|CONSOLE.*?WII/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_WIIWARE; - return true; - } - - return false; - } - - /** - * Work out if a release is Wii App - */ - public function isGameWii($releasename) - { - if (preg_match('/WWII.*?(?!WII)/i', $releasename)) - { - return false; - } - - else if (preg_match('/Wii/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_WII; - return true; - } - - return false; - } - - /** - * Work out if a release is 360DLC App - */ - public function isGameXBOX360DLC($releasename) - { - if (preg_match('/(DLC.*?xbox360|xbox360.*?DLC|XBLA.*?xbox360|xbox360.*?XBLA)/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_XBOX360DLC; - return true; - } - - return false; - } - - /** - * Work out if a release is 360 App - */ - public function isGameXBOX360($releasename) - { - if (preg_match('/XBOX360|x360/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_XBOX360; - return true; - } - - return false; - } - - /** - * Work out if a release is XBOX1 App - */ - public function isGameXBOX($releasename) - { - if (preg_match('/XBOX/i', $releasename)) - { - $this->tmpCat = Category::CAT_GAME_XBOX; - return true; - } - - return false; - } - - - /** - * Work out if a release is Music - */ - public function isMusic($releasename) - { - if($this->isHashed($releasename)){ return true; } - if($this->isMusicVideo($releasename)){ return true; } - if($this->isMusicLossless($releasename)){ return true; } - if($this->isMusicAudiobook($releasename)){ return true; } - if($this->isMusicMP3($releasename)){ return true; } - return false; - } - - /** - * Work out if a release is Music Video - */ - public function isMusicVideo($releasename) - { - - if (preg_match('/(HDTV|S\d{1,2}|\-1920)/i', $releasename)) - { - return false; - } - - else if (preg_match('/\-DDC\-|mbluray|\-VFI|m4vu|retail.*?(?!bluray.*?)x264|\-assass1ns|\-uva|(?!HDTV).*?\-SRP|x264.*?Fray|JESTERS|iuF|MDVDR|(?!HDTV).*?\-BTL|\-WMVA|\-GRMV|\-iLUV|x264\-(19|20)\d{2}/i', $releasename)) - { - $this->tmpCat = Category::CAT_MUSIC_VIDEO; - return true; - } - - return false; - } - - /** - * Work out if a release is Music Audiobook - */ - public function isMusicAudiobook($releasename) - { - if (preg_match('/(audiobook|\bABOOK\b)/i', $releasename)) - { - $this->tmpCat = Category::CAT_MUSIC_AUDIOBOOK; - return true; - } - - return false; - } - - - /** - * Work out if a release is MP3 Music - */ - public function isMusicMP3($releasename) - { - if (preg_match('/dvdrip|xvid|(x|h)264|720p|1080(i|p)|Bluray/i', $releasename)) - { - return false; - } - - if (preg_match('/( |\_)Int$|\-(19|20)\d{2}\-[a-z0-9]+$|^V A |Top.*?Charts|Promo CDS|Greatest(\_| )Hits|VBR|NMR|CDM|WEB(STREAM|MP3)|\-DVBC\-|\-CD\-|\-CDR\-|\-TAPE\-|\-Live\-\d{4}|\-DAB\-|\-LINE\-|CDDA|-Bootleg-|WEB\-\d{4}|\-CD\-|(\-|)EP\-|\-FM\-|2cd|\-Vinyl\-|\-SAT\-|\-LP\-|\-DE\-|\-cable\-|Radio\-\d{4}|Radio.*?Live\-\d{4}|\-SBD\-|\d{1,3}(CD|TAPE)/i', $releasename)) - { - $this->tmpCat = Category::CAT_MUSIC_MP3; - return true; - } - else if (preg_match('/^VA(\-|\_|\ )/i', $releasename)) - { - $this->tmpCat = Category::CAT_MUSIC_MP3; - return true; - } - return false; - } - - /** - * Work out if a release is FLAC Music - */ - public function isMusicLossless($releasename) - { - if (preg_match('/dvdrip|xvid|264|720p|1080|Bluray/i', $releasename)) - { - return false; - } - - if (preg_match('/Lossless|FLAC/i', $releasename)) - { - $this->tmpCat = Category::CAT_MUSIC_LOSSLESS; - return true; - } - return false; - } - - /** - * Work out if a release is an Ebook/Comic/Mag - */ - public function isBook($releasename) - { - if($this->isHashed($releasename)){ return true; } - if (preg_match('/dvdrip|xvid|x264/i', $releasename)){return false;} - if($this->isBookComic($releasename)){ return true; } - if($this->isBookMag($releasename)){ return true; } - if($this->isBookEbook($releasename)){ return true; } - return false; - } - - /** - * Work out if a release is a Comic - */ - public function isBookComic($releasename) - { - if (preg_match('/comic/i', $releasename)) - { - $this->tmpCat = Category::CAT_BOOK_COMICS; - return true; - } - return false; - } - - /** - * Work out if a release is a Magazine - */ - public function isBookMag($releasename) - { - if (preg_match('/Mag(s|azin|azine|azines)/i', $releasename)) - { - $this->tmpCat = Category::CAT_BOOK_MAGS; - return true; - } - return false; - } - - /** - * Work out if a release is a Ebook - */ - public function isBookEbook($releasename) - { - if (preg_match('/Ebook|E?\-book|\) WW|\[Springer\]| epub|ISBN/i', $releasename)) - { - $this->tmpCat = Category::CAT_BOOK_EBOOK; - return true; - } - return false; - } - -} diff --git a/test/files to copy/www/lib/framework/db.php b/test/files to copy/www/lib/framework/db.php deleted file mode 100755 index 0fcab57fe..000000000 --- a/test/files to copy/www/lib/framework/db.php +++ /dev/null @@ -1,242 +0,0 @@ -select_db(DB_NAME) - or die("Fatal error: could not select database! Check your config."); - - DB::$mysqli->set_charset("utf8"); - - DB::$usingInnoDB = defined('DB_INNODB') ? DB_INNODB : false; - - DB::$initialized = true; - } - } - - public function getBatchSize() - { - return DB::$batchSize; - } - - public function escapeString($str) - { - return "'" . DB::$mysqli->real_escape_string($str) . "'"; - } - - public function makeLookupTable($rows, $keycol) - { - $arr = array(); - foreach ($rows as $row) - $arr[$row[$keycol]] = $row; - return $arr; - } - - public function queryInsert($query, $returnlastid = true) - { - if($query=="") - return false; - - $result = DB::$mysqli->query($query); - return ($returnlastid) ? DB::$mysqli->insert_id : $result; - } - - public function queryOneRow($query, $useCache = false, $cacheTTL = '') - { - if($query=="") - return false; - - $rows = $this->query($query, $useCache, $cacheTTL); - return ($rows ? $rows[0] : false); - } - - public function query($query, $useCache = false, $cacheTTL = '') - { - if($query=="") - return false; - - if ($useCache) { - $cache = new Cache(); - if ($cache->enabled && $cache->exists($query)) { - $ret = $cache->fetch($query); - if ($ret !== false) - return $ret; - } - } - - $result = DB::$mysqli->query($query); - - - if ($result === false || $result === true) - return array(); - - $rows = array(); - - while ($row = $this->getAssocArray($result)) - $rows[] = $row; - - $this->freeResult($result); - - if ($useCache) - if ($cache->enabled) - $cache->store($query, $rows, $cacheTTL); - - return $rows; - } - public function queryDirect($query, $unbuffered = false) - { - if($query=="") - return false; - - if($unbuffered) - { - $ret = DB::$mysqli->query($query, MYSQLI_USE_RESULT); - } - else - { - $ret = DB::$mysqli->query($query); - } - - return $ret; - } - - public function freeResult($result) - { - $result->free_result(); - } - //*addedd from nZEDb for testing - public function fetchArray($result) - { - return (is_null($result) ? null : $result->fetch_array()); - } - //* end of insert for testing - public function getNumRows($result) - { - return $result->num_rows; - } - - public function disableAutoCommit() - { - if (DB::$usingInnoDB == false) - return; - - DB::$mysqli->autocommit(false); - } - - public function disableForeignKeyChecks() - { - if (DB::$usingInnoDB == false) - return; - - $this->query("SET foreign_key_checks=0;"); - } - - public function enableForeignKeyChecks() - { - if (DB::$usingInnoDB == false) - return; - - $this->query("SET foreign_key_checks=1;"); - } - - public function commit($enableAutoCommit = true) - { - if (DB::$usingInnoDB == false) - return; - - DB::$mysqli->commit(); - - if ($enableAutoCommit == true) - $this->enableAutoCommit(); - } - - public function rollback($enableAutoCommit = true) - { - if (DB::$usingInnoDB == false) - return; - - DB::$mysqli->rollback(); - - if ($enableAutoCommit == true) - $this->enableAutoCommit(); - } - - public function enableAutoCommit() - { - if (DB::$usingInnoDB == false) - return; - - DB::$mysqli->autocommit(true); - } - - public function usingInnoDB() - { - return DB::$usingInnoDB; - } - - public function getAssocArray($result) - { - return $result->fetch_assoc(); - } - - public function getRow($result) - { - return $result->fetch_row(); - } - - public function optimise($force = false) - { - $ret = array(); - if ($force) - $alltables = $this->query("show table status"); - else - $alltables = $this->query("show table status where Data_free != 0"); - - foreach ($alltables as $tablename) - { - $ret[] = $tablename['Name']; - if (strtolower($tablename['Engine']) == "myisam") - $this->queryDirect("REPAIR TABLE `" . $tablename['Name'] . "`"); - - $this->queryDirect("OPTIMIZE TABLE `" . $tablename['Name'] . "`"); - $this->queryDirect("ANALYZE TABLE `" . $tablename['Name'] . "`"); - } - - return $ret; - } - - public function getAffectedRows() - { - return DB::$mysqli->affected_rows; - } - - public function getLastError() - { - return DB::$mysqli->error; - } -} diff --git a/test/files to copy/www/lib/groups.php b/test/files to copy/www/lib/groups.php deleted file mode 100755 index ddbbde9f3..000000000 --- a/test/files to copy/www/lib/groups.php +++ /dev/null @@ -1,291 +0,0 @@ -query(sprintf("SELECT groups.*, COALESCE(rel.num, 0) AS num_releases - FROM groups - LEFT OUTER JOIN - ( SELECT groupID, COUNT(ID) AS num FROM releases group by groupID ) rel ON rel.groupID = groups.ID - ORDER BY %s",$orderby)); - } - - /** - * Get all group rows for use in a select list. - */ - public function getGroupsForSelect() - { - $db = new DB(); - $categories = $db->query("SELECT * FROM groups WHERE active = 1 ORDER BY name"); - $temp_array = array(); - - $temp_array[-1] = "--Please Select--"; - - foreach($categories as $category) - $temp_array[$category["name"]] = $category["name"]; - - return $temp_array; - } - - /** - * Get a group row by its ID. - */ - public function getByID($id) - { - $db = new DB(); - return $db->queryOneRow(sprintf("select * from groups where ID = %d ", $id)); - } - - /** - * Get all active group rows. - */ - public function getActive() - { - $db = new DB(); - return $db->query("SELECT * FROM groups WHERE active = 1 ORDER BY name"); - } - - /** - * Get a group row by name. - */ - public function getByName($grp) - { - $db = new DB(); - return $db->queryOneRow(sprintf("select * from groups where name = '%s' ", $grp)); - } - - public function getByNameByID($id) - { - $db = new DB(); - $res = $db->queryOneRow(sprintf("select name from groups where ID = %d ", $id)); - return $res["name"]; - } - - /** - * Get count of all groups, filter by name. - */ - public function getCount($groupname="", $activeonly=false) - { - $db = new DB(); - - $grpsql = ''; - if ($groupname != "") - $grpsql .= sprintf("and groups.name like %s ", $db->escapeString("%".$groupname."%")); - - if ($activeonly == true) - $grpsql .= "and active=1 "; - - $res = $db->queryOneRow(sprintf("select count(ID) as num from groups where 1=1 %s", $grpsql)); - return $res["num"]; - } - - /** - * Get groups rows for browse list by limit. - */ - public function getRange($start, $num, $groupname="", $activeonly=false) - { - $db = new DB(); - if ($start === false) - $limit = ""; - else - $limit = " LIMIT ".$start.",".$num; - - $grpsql = ''; - if ($groupname != "") - $grpsql .= sprintf("and groups.name like %s ", $db->escapeString("%".$groupname."%")); - if ($activeonly == true) - $grpsql .= "and active=1 "; - - $sql = sprintf("SELECT groups.*, COALESCE(rel.num, 0) AS num_releases - FROM groups - LEFT OUTER JOIN - ( - SELECT groupID, COUNT(ID) AS num FROM releases group by groupID - ) rel ON rel.groupID = groups.ID WHERE 1=1 %s ORDER BY groups.name ".$limit, $grpsql); - return $db->query($sql); - } - - /** - * Add a new group row. - */ - public function add($group) - { - $db = new DB(); - - if ($group["minfilestoformrelease"] == "" || $group["minfilestoformrelease"] == "0") - $minfiles = 'null'; - else - $minfiles = $group["minfilestoformrelease"] + 0; - - if ($group["minsizetoformrelease"] == "" || $group["minsizetoformrelease"] == "0") - $minsizetoformrelease = 'null'; - else - $minsizetoformrelease = $db->escapeString($group["minsizetoformrelease"]); - - if ($group["backfill_target"] == "" || $group["backfill_target"] == "0") - $backfill_target = '0'; - else - $backfill_target = $group["backfill_target"] + 0; - - $first = (isset($group["first_record"]) ? $group["first_record"] : "0"); - $last = (isset($group["last_record"]) ? $group["last_record"] : "0"); - - $sql = sprintf("insert into groups (name, description, first_record, last_record, last_updated, active, minfilestoformrelease, minsizetoformrelease, backfill_target) values (%s, %s, %s, %s, null, %d, %s, %s, %d) ",$db->escapeString($group["name"]), $db->escapeString($group["description"]), $db->escapeString($first), $db->escapeString($last), $group["active"], $minfiles, $minsizetoformrelease, $backfill_target); - return $db->queryInsert($sql); - } - - /** - * Delete a group. - */ - public function delete($id) - { - $db = new DB(); - return $db->query(sprintf("delete from groups where ID = %d", $id)); - } - - /** - * Reset all stats about a group, like its first_record. - */ - public function reset($id) - { - $db = new DB(); - return $db->query(sprintf("update groups set backfill_target=0, first_record=0, first_record_postdate=null, last_record=0, last_record_postdate=null, last_updated=null where ID = %d", $id)); - } - - /** - * Reset all stats about a group and delete all releases and binaries associated with that group. - */ - public function purge($id) - { - require_once(WWW_DIR."/lib/binaries.php"); - - $db = new DB(); - $releases = new Releases(); - $binaries = new Binaries(); - - $this->reset($id); - - $rels = $db->query(sprintf("select ID from releases where groupID = %d", $id)); - foreach ($rels as $rel) - $releases->delete($rel["ID"]); - - $bins = $db->query(sprintf("select ID from binaries where groupID = %d", $id)); - foreach ($bins as $bin) - $binaries->delete($bin["ID"]); - } - - /** - * Update a group row. - */ - public function update($group) - { - $db = new DB(); - - if ($group["minfilestoformrelease"] == "" || $group["minfilestoformrelease"] == "0") - $minfiles = 'null'; - else - $minfiles = $group["minfilestoformrelease"] + 0; - - if ($group["minsizetoformrelease"] == "" || $group["minsizetoformrelease"] == "0") - $minsizetoformrelease = 'null'; - else - $minsizetoformrelease = $db->escapeString($group["minsizetoformrelease"]); - - return $db->query(sprintf("update groups set name=%s, description = %s, backfill_target = %s , active=%d, minfilestoformrelease=%s, minsizetoformrelease=%s where ID = %d ",$db->escapeString($group["name"]), $db->escapeString($group["description"]), $db->escapeString($group["backfill_target"]),$group["active"] , $minfiles, $minsizetoformrelease, $group["id"] )); - } - - /** - * Update the list of newsgroups from nntp provider matching a regex and return an array of messages. - */ - function addBulk($groupList, $active = 1) - { - require_once(WWW_DIR."/lib/binaries.php"); - require_once(WWW_DIR."/lib/nntp.php"); - - $ret = array(); - - if ($groupList == "") - { - $ret[] = "No group list provided."; - } - else - { - $db = new DB(); - $nntp = new Nntp; - if (!$nntp->doConnect()) { - $ret[] = "Failed to get NNTP connection"; - return $ret; - } - $groups = $nntp->getGroups(); - $nntp->doQuit(); - - $regfilter = "/(" . str_replace (array ('.','*'), array ('\.','.*?'), $groupList) . ")$/"; - - foreach($groups AS $group) - { - if (preg_match ($regfilter, $group['group']) > 0) - { - $res = $db->queryOneRow(sprintf("SELECT ID FROM groups WHERE name = %s ", $db->escapeString($group['group']))); - if($res) - { - - $db->query(sprintf("UPDATE groups SET active = %d where ID = %d", $active, $res["ID"])); - $ret[] = array ('group' => $group['group'], 'msg' => 'Updated'); - } - else - { - $desc = ""; - $db->queryInsert(sprintf("INSERT INTO groups (name, description, active) VALUES (%s, %s, %d)", $db->escapeString($group['group']), $db->escapeString($desc), $active)); - $ret[] = array ('group' => $group['group'], 'msg' => 'Created'); - } - } - } - } - return $ret; - } - - /** - * Update a group to be active/inactive. - */ - public function updateGroupStatus($id, $status = 0) - { - $db = new DB(); - $db->query(sprintf("UPDATE groups SET active = %d WHERE id = %d", $status, $id)); - $status = ($status == 0) ? 'deactivated' : 'activated'; - return "Group $id has been $status."; - } -} diff --git a/test/files to copy/www/lib/nfo.php b/test/files to copy/www/lib/nfo.php deleted file mode 100755 index 837a5d386..000000000 --- a/test/files to copy/www/lib/nfo.php +++ /dev/null @@ -1,712 +0,0 @@ -use_fuzzy=$use_fuzzy; - $this->use_obfuscated=$use_obfuscated; - $this->verbose=$verbose; - } - - private function nfo_scan(&$nzbInfo){ - // - // Phase 1, iterate over nzb file for a relative - // match on a possible nfo file - // - 1 segment - // - within byte size - // - - // Array of all possible matches to return - $nfo_idx = array(); - - // Search for all entries that have a single segment - if (empty($nzbInfo->segmentfiles)) - // Nothing to Return - return array(); - - // Fetch Meta Information - 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; - - $unordered_list[] = array( - "name" => $name, - "subject" => $segment['subject'], - "bytes" => $segment['filesize'], - "segment" => $segment['segments'], - "groups" => $segment['groups'] - ); - } - - // - // Filter built list above based on subject line info - // hence... eliminate par2, nzb ... etc files - // - // processing is done in 2 steps, the first step finds the - // most likely .nfo files, while the second keeps a backup - // of potential others in the unlikelyhood the content - // parsed here is bad - // - foreach($unordered_list as $idx => $n){ - if (preg_match("/\.(nfo)([^a-z0-9]+|$)/i", $n["subject"])){ - 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 (preg_match("/\.(sfv)([^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] "; - $nfo_idx[]=$n; - } - } - - // 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 (preg_match("/\.(txt|diz)([^a-z0-9]+|$)/i", $n["subject"])){ - if($this->verbose) echo "[fuzz] "; - $nfo_idx[]=$n; - } - } - - // Return array of matched content in order (aprox) - // from very possible to... possible... - return $nfo_idx; - } - - private function is_binary(&$raw){ - // Returns true if data passed in is binary, otherwise - // returns false, - $has_binary = ( - 0 or substr_count($raw, "^\r\n")/512 > 0.3 - or substr_count($raw, "^ -~")/512 > 0.3 - or substr_count($raw, "\x00") > 0 - ); - - 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) - { - // not binary, we decoded it - // we're dealing with a utf-16 type file... - // store it as utf-8 - $raw = $result; - return false; - } - } - - // Return the binary flag - return ($has_binary)?true:false; - } - - 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){ - // scan a content and return true if it is detected to be - // an sfv file, otherwise return false - - // First we identify acceptable sfv lines, anything that - // does not match against the below causes this function to - // exit gracefully and report that were not dealing with - // an sfv file - $sfv_regex = array( - // the sfv information itself - '/^\s*([^; \t]+)\s+([^; \t]+)[ \t]*(;|$)/', - // sfv comments - '/^\s*;/', - // empty lines that contain nothing - '/^$/', - ); - // itreate over each line of file, if all regex's match - // 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)){ - $matches=true; - break; - } - if(!$matches) - return false; - } - return true; - } - - 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 - // must be passed into the function. - - $db = new DB(); - $db->disableAutoCommit(); - foreach($blobhash as $uid => $blob){ - $query = sprintf( - "REPLACE INTO releasenfo (ID, releaseID, binaryID, nfo) ". - "VALUES (NULL, %d, 0, compress(%s));", - $uid, $db->escapeString($blob)); - $id = $db->queryInsert($query); - if(!$id){ - if($this->verbose) echo "!"; - }else{ - $query = sprintf("UPDATE releases SET releasenfoID = %d WHERE ID = %d LIMIT 1", - $id, $uid); - $res = $db->query($query); - if($this->verbose) echo "s"; - } - } - $db->commit(false); - - // Now we update the database with entries that have no nfo files - // associated with the release - foreach($removed as $uid){ - $res = $this->setNfoMissing($uid); - if($db->getAffectedRows() <= 0){ - if($this->verbose) echo "!"; - }else{ - if($this->verbose) echo "s"; - } - } - $db->commit(); // re-enables auto-commit - } - - private function parse_blobs(&$nfometa, &$nfoblob){ - // Parses an array of array of blobs and determines the most - // ideal nfo from them. - // - // $nfoblob is expected as follows - // - // $nfoblob = array( - // [] = array( - // [0] = , - // [1] = , - // ... - // ), - // [] = array( - // [0] = , - // ), - // ... - // ) - // - // Meanwhile, $nfometa is expected as follows: - // $nfometa = array( - // [] = array( - // [groups] = array( - // "alt.binaries.mygroupa", - // "alt.binaries.mygroupb", - // "alt.binaries.mygroupc", - // ... - // ) - // [segment] = array(), - // [groups] = array( - // "alt.binaries.mygroupa", - // "alt.binaries.mygroupb", - // ... - // ) - // ), - // [] = array( - // [groups] = array( - // "alt.binaries.mygroupa", - // ... - // ) - // [segment] = array(), - // ), - // ... - // The function strips indexes that appear invalid - // and stores the most ideal match per release - - $parsed_blob = array(); - $parsed_meta = array(); - - foreach($nfometa as $uid => $info){ - $ideal = Null; - $tossed = 0; - $total = count($info); - foreach($info as $idx => $entry){ - // No magic yet here... to come soon! - // for now we save first 'valid' entry - - // Some simple checks right off the top... if there is - // 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 '-'; - continue; - } - if(!array_key_exists($idx, $nfoblob[$uid])){ - if($this->verbose) echo '-'; - continue; - } - if($nfoblob[(string)$uid][$idx] === Null){ - 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 '-'; - continue; - } - - // We do not want to pick up sfv files - if($this->is_sfv($nfoblob[$uid][$idx])){ - 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 '-'; - continue; - } - // Ideally if code reaches this far - // we can assume we've matched and we - // san skip further parsing - $ideal = $idx; - break; - } - - if($ideal !== Null){ - // An ideal match was found - $parsed_blob[(string)$uid] = $nfoblob[$uid][$ideal]; - $parsed_meta[(string)$uid] = $nfometa[$uid][$ideal]; - if($this->verbose) echo '+'; - }else{ - // No valid data - unset($parsed_blob[(string)$uid]); - unset($parsed_meta[(string)$uid]); - } - } - - // perform swap with new parsed data by elminating the array containing - // the possible matches with the absolute match itself... - // no longer is anyone dealing with an array of array after calling - // this function - $nfoblob = $parsed_blob; - $nfometa = $parsed_meta; - - return count($nfoblob); - } - - 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. - // nfometa is an array of arrays simiar to the following - // structure: - // - // The list is structured in such a way that the most ideal - // matches are at the front, while less likely ones at the - // back of the array - // - // $nfometa = array( - // [] = array( - // [groups] = array( - // "alt.binaries.mygroupa", - // "alt.binaries.mygroupb", - // "alt.binaries.mygroupc", - // ... - // ) - // [segment] = array(), - // [groups] = array( - // "alt.binaries.mygroupa", - // "alt.binaries.mygroupb", - // ... - // ) - // ), - // [] = array( - // [groups] = array( - // "alt.binaries.mygroupa", - // ... - // ) - // [segment] = array(), - // ), - // ... - // ) - $nntp = new Nntp(); - - // Connect to server (we throw an exception if we fail) which - // is caught upstairs with the nfo_grab() function - // no error handling is needed here - $nntp->doConnect(1, true); - foreach($nfometa as $uid => $matches){ - $blobhash[$uid] = array(); - foreach($matches as $idx => $match){ - $fetched = false; - foreach($match["groups"] as $group){ - // Don not try other groups if we already got it - 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 '*'; - continue; - } - // Mark that we fetched it to prevent fetching more - // of the same thing - $fetched = true; - if($this->verbose) echo '.'; - - // Update blob with decrypted version and store - if ($this->is_binary($blob)){ - // Binary data is not acceptable, we only - // work with text from here on out. - continue; - } - // Read-able ascii at this point... store it - $blobhash[$uid][$idx] = $blob; - } - if(!$fetched) - // handle empty/failed segments - $blobhash[$uid][$idx] = Null; - } - } - $nntp->doQuit(); - } - - 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() - // in a try catch block with a silent exception catcher - $retries = nfo::USENET_RETRY_COUNT; - set_error_handler('nfoHandleError'); - $_blobhash = array(); - while($retries >0){ - try{ - $this->_nfo_grab($nfometa, $_blobhash); - break; - }catch (Exception $e){ - // Connection lost - if($this->verbose) echo sprintf("\n%s Connection lost to usenet (%d retries left).\n", - 'NfoProc', $retries); - // Decrement retry count - $retries--; - // Reset blobhash - $_blobhash = array(); - continue; - } - } - // Restore handler as any future errors really are... code errors :) - restore_error_handler(); - - if($retries>0){ - foreach ($_blobhash as $k => $v) - $blobhash[(string)$k]=$v; - return true; - } - return false; - } - - 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. - // - // nzb files are further parsed for nfo segments that can - // be extracted and applied to the release - $nzb = new NZB(); - $db = new DB(); - - // How many releases to handle at a time - $batch=Nfo::NNTP_BATCH_COUNT; - - // Build NFO List - $nfometa = array(); - - // Missing NFO Query (oldest first so they don't expire on us) - $mnfo = "SELECT ID,guid, name FROM releases r ". - "WHERE r.releasenfoID = ".Nfo::FLAG_NFO_PENDING. - " ORDER BY postdate DESC"; - - if ($limit !==Null and $limit > 0) - $mnfo .= " LIMIT $limit"; - - $res = $db->query($mnfo); - if($res){ - foreach($res as $r){ - $nzbfile = $nzb->getNZBPath($r["guid"]); - if(!is_file($nzbfile)){ - if($this->verbose) echo sprintf("%s Missing NZB File: %d/%s ...\n", - 'NfoProc', intval($r["ID"]), $r["name"]); - $this->setNfoMissing($r["ID"]); - continue; - } - - $nzbInfo = new NzbInfo(); - if (!$nzbInfo->loadFromFile($nzbfile)) - { - 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; - - $filename = basename($nzbfile); - 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) echo "nfo missing.\n"; - $this->setNfoMissing($r["ID"]); - continue; - } - }else{ - if($this->verbose) echo "corrupt nzb.\n"; - $this->setNfoMissing($r["ID"]); - continue; - } - if($this->verbose) echo count($matches)." possible nfo(s).\n"; - $processed++; - - // Hash Matches by Release ID - $nfometa[(string)$r["ID"]] = $matches; - - if(!($processed%$batch)) - { - $nfoblob = array(); - if($this->verbose) echo "NfoProc : Retrieval ..."; - 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) echo "\n"; - - // Reset nfo list array - $nfometa = array(); - } - } - if(($processed%$batch)){ - $nfoblob = array(); - if($this->verbose) echo "NfoProc : Retrieval ..."; - 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) echo "\n"; - } - } - return true; - } - //Add release nfo, imported from nZEDb - public function addReleaseNfo($relid) - { - $db = new DB(); - return $db->queryInsert(sprintf("INSERT IGNORE INTO releasenfo (releaseID) VALUE (%d)", $relid)); - } - // end of imported part - - //Add isNFO, imported from nZEDb - // Confirm that the .nfo file is not something else. - public function isNFO($possibleNFO) - { - $ok = false; - if ($possibleNFO !== false) - { - if (!preg_match('/( 15) - { - // Check if it's a picture - EXIF. - if (@exif_imagetype($possibleNFO) == false) - { - // Check if it's a picture - JFIF. - if ($this->check_JFIF($possibleNFO) == false) - { - // Check if it's a par2. - $par2info = new Par2Info(); - $par2info->setData($possibleNFO); - if ($par2info->error) - { - $ok = true; - } - } - } - } - } - } - } - return $ok; - } - - // Check if the possible NFO is a JFIF. - function check_JFIF($filename) - { - $fp = @fopen($filename, 'r'); - if ($fp) - { - // JFIF often (but not always) starts at offset 6. - if (fseek($fp, 6) == 0) - { - // JFIF header is 16 bytes. - if (($bytes = fread($fp, 16)) !== false) - { - // Make sure it is JFIF header. - if (substr($bytes, 0, 4) == "JFIF") - return true; - else - return false; - } - } - } - } - //end of import - /** - * Delete a releasenfo row. - */ - public function deleteReleaseNfo($relid) - { - $db = new DB(); - return $db->query(sprintf("delete from releasenfo where releaseID = %d", $relid)); - } - - /** - * Mark a release as missing so it isn't ever parsed again - */ - private function setNfoMissing($relid) - { - $db = new DB(); - $q = sprintf("UPDATE releases SET releasenfoID = %d ". - "WHERE ID = %d", Nfo::FLAG_NFO_MISSING, $relid); - return $db->query($q); - } - - /** - * Returns the nfo from the database (blob) - */ - public function getNfo($relid, &$nfoout) - { - $db = new DB(); - // Has NFO Query - $mnfo = "SELECT uncompress(rn.nfo) as nfo FROM releases r ". - "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'])) - { - $nfoout=$res['nfo']; - return true; - } - return false; - } - - /** - * Process Nfo's - */ - public function processNfoFiles($batch=50) - { - $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); - - return $total; - } -} diff --git a/test/files to copy/www/lib/releases.php b/test/files to copy/www/lib/releases.php deleted file mode 100755 index a8d8bc9b2..000000000 --- a/test/files to copy/www/lib/releases.php +++ /dev/null @@ -1,2126 +0,0 @@ - 0) - { - $n = array(); - foreach($names as $nm) - $n[] = " searchname = ". $db->escapeString($nm); - - $nsql = "( ".implode(' or ', $n)." )"; - } - - $sql = sprintf(" SELECT releases.*, CONCAT(cp.title, ' > ', c.title) AS category_name, - m.ID AS movie_id, m.title, m.rating, m.cover, m.plot, m.year, m.genre, m.director, m.actors, m.tagline, - mu.ID AS music_id, mu.title as mu_title, mu.cover as mu_cover, mu.year as mu_year, mu.artist as mu_artist, mu.tracks as mu_tracks, mu.review as mu_review, - ep.ID AS ep_id, ep.showtitle as ep_showtitle, ep.airdate as ep_airdate, ep.fullep as ep_fullep, ep.overview as ep_overview, - tvrage.imgdata as rage_imgdata, tvrage.ID as rg_ID - FROM releases - LEFT OUTER JOIN category c ON c.ID = releases.categoryID - LEFT OUTER JOIN category cp ON cp.ID = c.parentID - LEFT OUTER JOIN movieinfo m ON m.imdbID = releases.imdbID - LEFT OUTER JOIN musicinfo mu ON mu.ID = releases.musicinfoID - LEFT OUTER JOIN episodeinfo ep ON ep.ID = releases.episodeinfoID - LEFT OUTER JOIN tvrage ON tvrage.rageID = releases.rageID - where %s", $nsql); - - return $db->queryDirect($sql); - } - - /** - * Get a count of releases for pager. used in admin manage list - */ - public function getCount() - { - $db = new DB(); - $res = $db->queryOneRow("select count(ID) as num from releases"); - return $res["num"]; - } - - /** - * Get a range of releases. used in admin manage list - */ - public function getRange($start, $num) - { - $db = new DB(); - - if ($start === false) - $limit = ""; - else - $limit = " LIMIT ".$start.",".$num; - - return $db->query(" SELECT releases.*, concat(cp.title, ' > ', c.title) as category_name from releases left outer join category c on c.ID = releases.categoryID left outer join category cp on cp.ID = c.parentID order by postdate desc".$limit); - } - - /** - * Get a count of releases for main browse pager. - */ - public function getBrowseCount($cat, $maxage=-1, $excludedcats=array(), $grp=array()) - { - $db = new DB(); - - $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - } - - if ($maxage > 0) - $maxage = sprintf(" and postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; - - $grpsql = ""; - if (count($grp) > 0) - { - $grpsql = " and ("; - foreach ($grp as $grpname) - { - $grpsql.= sprintf(" groups.name = %s or ", $db->escapeString(str_replace("a.b.", "alt.binaries.", $grpname))); - } - $grpsql.= "1=2 )"; - } - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and categoryID not in (".implode(",", $excludedcats).")"; - - $sql = sprintf("select count(releases.ID) as num from releases left outer join groups on groups.ID = releases.groupID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s", $catsrch, $maxage, $exccatlist, $grpsql); - $res = $db->queryOneRow($sql, true); - return $res["num"]; - } - - /** - * Get a releases for main browse pages. - */ - public function getBrowseRange($cat, $start, $num, $orderby, $maxage=-1, $excludedcats=array(), $grp=array()) - { - $db = new DB(); - - if ($start === false) - $limit = ""; - else - $limit = " LIMIT ".$start.",".$num; - - $usecatindex = ""; - $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - $usecatindex = " use index (ix_releases_categoryID) "; - } - - $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and postdate > now() - interval %d day ", $maxage); - - $grpsql = ""; - if (count($grp) > 0) - { - $grpsql = "select ID from groups where ("; - foreach ($grp as $grpname) - $grpsql.= sprintf(" groups.name = %s or ", $db->escapeString(str_replace("a.b.", "alt.binaries.", $grpname))); - - $grpsql.= "1=2 )"; - - $grpres = $db->query($grpsql); - if (count($grpsql) > 0) - { - $grpsql = " and ( "; - foreach ($grpres as $grpresrow) - $grpsql.= sprintf(" groups.ID = %d or ", $grpresrow["ID"]); - - $grpsql = substr($grpsql, 0, strlen($grpsql) - 3)." ) "; - } - else - $grpsql = ""; - } - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and releases.categoryID not in (".implode(",", $excludedcats).")"; - - $order = $this->getBrowseOrder($orderby); - $sql = sprintf(" SELECT releases.*, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, rn.ID as nfoID, re.releaseID as reID, pre.ctime, pre.nuketype, coalesce(movieinfo.ID,0) as movieinfoID from releases %s left outer join groups on groups.ID = releases.groupID left outer join movieinfo on movieinfo.imdbID = releases.imdbID left outer join releaseaudio re on re.releaseID = releases.ID and re.audioID = 1 left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join category c on c.ID = releases.categoryID left outer join category cp on cp.ID = c.parentID left outer join predb pre on pre.ID = releases.preID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s order by %s %s".$limit, $usecatindex, $catsrch, $maxagesql, $exccatlist, $grpsql, $order[0], $order[1]); - return $db->query($sql, true); - } - - /** - * Get a column names browse list to be ordered by - */ - public function getBrowseOrder($orderby) - { - $order = ($orderby == '') ? 'posted_desc' : $orderby; - $orderArr = explode("_", $order); - switch($orderArr[0]) { - case 'cat': - $orderfield = 'categoryID'; - break; - case 'name': - $orderfield = 'searchname'; - break; - case 'size': - $orderfield = 'size'; - break; - case 'files': - $orderfield = 'totalpart'; - break; - case 'stats': - $orderfield = 'grabs'; - break; - case 'posted': - default: - $orderfield = 'postdate'; - break; - } - $ordersort = (isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1])) ? $orderArr[1] : 'desc'; - return array($orderfield, $ordersort); - } - - /** - * Get a list of available columns for sorting browse list - */ - public function getBrowseOrdering() - { - return array('name_asc', 'name_desc', 'cat_asc', 'cat_desc', 'posted_asc', 'posted_desc', 'size_asc', 'size_desc', 'files_asc', 'files_desc', 'stats_asc', 'stats_desc'); - } - - /** - * Get a range of releases. Used in nzb export - */ - public function getForExport($postfrom, $postto, $group, $cat) - { - $db = new DB(); - if ($postfrom != "") - { - $dateparts = explode("/", $postfrom); - if (count($dateparts) == 3) - $postfrom = sprintf(" and postdate > %s ", $db->escapeString($dateparts[2]."-".$dateparts[1]."-".$dateparts[0]." 00:00:00")); - else - $postfrom = ""; - } - - if ($postto != "") - { - $dateparts = explode("/", $postto); - if (count($dateparts) == 3) - $postto = sprintf(" and postdate < %s ", $db->escapeString($dateparts[2]."-".$dateparts[1]."-".$dateparts[0]." 23:59:59")); - else - $postto = ""; - } - - if ($group != "" && $group != "-1") - $group = sprintf(" and groupID = %d ", $group); - else - $group = ""; - - if ($cat != "" && $cat != "-1") - $cat = sprintf(" and categoryID = %d ", $cat); - else - $cat = ""; - - return $db->queryDirect(sprintf("SELECT searchname, guid, CONCAT(cp.title,'_',category.title) as catName FROM releases INNER JOIN category ON releases.categoryID = category.ID LEFT OUTER JOIN category cp ON cp.ID = category.parentID where 1 = 1 %s %s %s %s", $postfrom, $postto, $group, $cat)); - } - - /** - * Get the earliest release - */ - public function getEarliestUsenetPostDate() - { - $db = new DB(); - $row = $db->queryOneRow("SELECT DATE_FORMAT(min(postdate), '%d/%m/%Y') as postdate from releases"); - return $row["postdate"]; - } - - /** - * Get the most recent release - */ - public function getLatestUsenetPostDate() - { - $db = new DB(); - $row = $db->queryOneRow("SELECT DATE_FORMAT(max(postdate), '%d/%m/%Y') as postdate from releases"); - return $row["postdate"]; - } - - /** - * Get all groups for which there is a release for a html select - */ - public function getReleasedGroupsForSelect($blnIncludeAll = true) - { - $db = new DB(); - $groups = $db->query("select distinct groups.ID, groups.name from releases inner join groups on groups.ID = releases.groupID"); - $temp_array = array(); - - if ($blnIncludeAll) - $temp_array[-1] = "--All Groups--"; - - foreach($groups as $group) - $temp_array[$group["ID"]] = $group["name"]; - - return $temp_array; - } - - /** - * Get releases for all types of rss feeds - */ - public function getRss($cat, $num, $uid=0, $rageid, $anidbid, $airdate=-1) - { - $db = new DB(); - - $limit = " LIMIT 0,".($num > 100 ? 100 : $num); - - $cartsrch = ""; - $catsrch = ""; - - if (count($cat) > 0) - { - if ($cat[0] == -2) - { - $cartsrch = sprintf(" inner join usercart on usercart.userID = %d and usercart.releaseID = releases.ID ", $uid); - } - elseif ($cat[0] == -1) - { - } - else - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - } - } - - $rage = ($rageid > -1) ? sprintf(" and releases.rageID = %d ", $rageid) : ''; - $anidb = ($anidbid > -1) ? sprintf(" and releases.anidbID = %d ", $anidbid) : ''; - $airdate = ($airdate > -1) ? sprintf(" and releases.tvairdate >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ", $airdate) : ''; - - $sql = sprintf(" SELECT releases.*, rn.ID as nfoID, m.title as imdbtitle, m.cover, m.imdbID, m.rating, m.plot, m.year, m.genre, m.director, m.actors, g.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, coalesce(cp.ID,0) as parentCategoryID, mu.title as mu_title, mu.url as mu_url, mu.artist as mu_artist, mu.publisher as mu_publisher, mu.releasedate as mu_releasedate, mu.review as mu_review, mu.tracks as mu_tracks, mu.cover as mu_cover, mug.title as mu_genre, co.title as co_title, co.url as co_url, co.publisher as co_publisher, co.releasedate as co_releasedate, co.review as co_review, co.cover as co_cover, cog.title as co_genre, bo.title as bo_title, bo.url as bo_url, bo.publisher as bo_publisher, bo.author as bo_author, bo.publishdate as bo_publishdate, bo.review as bo_review, bo.cover as bo_cover from releases left outer join category c on c.ID = releases.categoryID left outer join category cp on cp.ID = c.parentID left outer join groups g on g.ID = releases.groupID left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join movieinfo m on m.imdbID = releases.imdbID and m.title != '' left outer join musicinfo mu on mu.ID = releases.musicinfoID left outer join genres mug on mug.ID = mu.genreID left outer join bookinfo bo on bo.ID = releases.bookinfoID left outer join consoleinfo co on co.ID = releases.consoleinfoID left outer join genres cog on cog.ID = co.genreID %s where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s order by postdate desc %s" ,$cartsrch, $catsrch, $rage, $anidb, $airdate, $limit); - return $db->query($sql, true); - } - - /** - * Get releases in users 'my tv show' rss feed - */ - public function getShowsRss($num, $uid=0, $excludedcats=array(), $airdate=-1) - { - $db = new DB(); - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and releases.categoryID not in (".implode(",", $excludedcats).")"; - - $usershows = $db->query(sprintf("select rageID, categoryID from userseries where userID = %d", $uid), true); - $usql = '(1=2 '; - foreach($usershows as $ushow) - { - $usql .= sprintf('or (releases.rageID = %d', $ushow['rageID']); - if ($ushow['categoryID'] != '') - { - $catsArr = explode('|', $ushow['categoryID']); - if (count($catsArr) > 1) - $usql .= sprintf(' and releases.categoryID in (%s)', implode(',',$catsArr)); - else - $usql .= sprintf(' and releases.categoryID = %d', $catsArr[0]); - } - $usql .= ') '; - } - $usql .= ') '; - - $airdate = ($airdate > -1) ? sprintf(" and releases.tvairdate >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ", $airdate) : ''; - - $limit = " LIMIT 0,".($num > 100 ? 100 : $num); - - $sql = sprintf(" SELECT releases.*, tvr.rageID, tvr.releasetitle, epinfo.overview, epinfo.director, epinfo.gueststars, epinfo.writer, epinfo.rating, epinfo.fullep, epinfo.showtitle, epinfo.tvdbID as ep_tvdbID, g.name as group_name, concat(cp.title, '-', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, coalesce(cp.ID,0) as parentCategoryID - FROM releases FORCE INDEX (ix_releases_rageID) - left outer join category c on c.ID = releases.categoryID - left outer join category cp on cp.ID = c.parentID - left outer join groups g on g.ID = releases.groupID - left outer join (SELECT ID, releasetitle, rageid FROM tvrage GROUP BY rageid) tvr on tvr.rageID = releases.rageID - left outer join episodeinfo epinfo on epinfo.ID = releases.episodeinfoID - inner join - ( select ID from - ( select id, rageID, categoryID, season, episode from releases where %s order by season desc, episode desc, postdate asc ) releases - group by rageID, season, episode, categoryID - ) z on z.id = releases.ID - where %s %s %s - and releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') - order by postdate desc %s" , $usql, $usql, $exccatlist, $airdate, $limit); - return $db->query($sql); - } - - /** - * Get releases in users 'my movies' rss feed - */ - public function getMyMoviesRss($num, $uid=0, $excludedcats=array()) - { - $db = new DB(); - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and releases.categoryID not in (".implode(",", $excludedcats).")"; - - $usermovies = $db->query(sprintf("select imdbID, categoryID from usermovies where userID = %d", $uid), true); - $usql = '(1=2 '; - foreach($usermovies as $umov) - { - $usql .= sprintf('or (releases.imdbID = %d', $umov['imdbID']); - if ($umov['categoryID'] != '') - { - $catsArr = explode('|', $umov['categoryID']); - if (count($catsArr) > 1) - $usql .= sprintf(' and releases.categoryID in (%s)', implode(',',$catsArr)); - else - $usql .= sprintf(' and releases.categoryID = %d', $catsArr[0]); - } - $usql .= ') '; - } - $usql .= ') '; - - $limit = " LIMIT 0,".($num > 100 ? 100 : $num); - - $sql = sprintf(" SELECT releases.*, mi.title as releasetitle, g.name as group_name, concat(cp.title, '-', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, coalesce(cp.ID,0) as parentCategoryID - FROM releases - left outer join category c on c.ID = releases.categoryID - left outer join category cp on cp.ID = c.parentID - left outer join groups g on g.ID = releases.groupID - left outer join movieinfo mi on mi.imdbID = releases.imdbID - where %s %s - and releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') - order by postdate desc %s" , $usql, $exccatlist, $limit); - return $db->query($sql); - } - - /** - * Get range of releases in users 'my tvshows' - */ - public function getShowsRange($usershows, $start, $num, $orderby, $maxage=-1, $excludedcats=array()) - { - $db = new DB(); - - if ($start === false) - $limit = ""; - else - $limit = " LIMIT ".$start.",".$num; - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and releases.categoryID not in (".implode(",", $excludedcats).")"; - - $usql = '(1=2 '; - foreach($usershows as $ushow) - { - $usql .= sprintf('or (releases.rageID = %d', $ushow['rageID']); - if ($ushow['categoryID'] != '') - { - $catsArr = explode('|', $ushow['categoryID']); - if (count($catsArr) > 1) - $usql .= sprintf(' and releases.categoryID in (%s)', implode(',',$catsArr)); - else - $usql .= sprintf(' and releases.categoryID = %d', $catsArr[0]); - } - $usql .= ') '; - } - $usql .= ') '; - - $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and releases.postdate > now() - interval %d day ", $maxage); - - $order = $this->getBrowseOrder($orderby); - $sql = sprintf(" SELECT releases.*, concat(cp.title, '-', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, pre.ctime, pre.nuketype, rn.ID as nfoID, re.releaseID as reID from releases left outer join releasevideo re on re.releaseID = releases.ID left outer join groups on groups.ID = releases.groupID left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join category c on c.ID = releases.categoryID left outer join predb pre on pre.ID = releases.preID left outer join category cp on cp.ID = c.parentID where %s %s and releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s order by %s %s".$limit, $usql, $exccatlist, $maxagesql, $order[0], $order[1]); - return $db->query($sql, true); - } - - /** - * Get count of releases in users 'my tvshows' for pager - */ - public function getShowsCount($usershows, $maxage=-1, $excludedcats=array()) - { - $db = new DB(); - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and releases.categoryID not in (".implode(",", $excludedcats).")"; - - $usql = '(1=2 '; - foreach($usershows as $ushow) - { - $usql .= sprintf('or (releases.rageID = %d', $ushow['rageID']); - if ($ushow['categoryID'] != '') - { - $catsArr = explode('|', $ushow['categoryID']); - if (count($catsArr) > 1) - $usql .= sprintf(' and releases.categoryID in (%s)', implode(',',$catsArr)); - else - $usql .= sprintf(' and releases.categoryID = %d', $catsArr[0]); - } - $usql .= ') '; - } - $usql .= ') '; - - $maxagesql = ""; - if ($maxage > 0) - $maxagesql = sprintf(" and releases.postdate > now() - interval %d day ", $maxage); - - $res = $db->queryOneRow(sprintf(" SELECT count(releases.ID) as num from releases where %s %s and releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s", $usql, $exccatlist, $maxagesql), true); - return $res["num"]; - } - - /** - * Delete one or more releases. - */ - public function delete($id, $isGuid=false) - { - $db = new DB(); - $users = new Users(); - $s = new Sites(); - $nfo = new Nfo(); - $site = $s->get(); - $rf = new ReleaseFiles(); - $re = new ReleaseExtra(); - $rc = new ReleaseComments(); - $ri = new ReleaseImage(); - - if (!is_array($id)) - $id = array($id); - - foreach($id as $identifier) - { - // - // delete from disk. - // - $rel = ($isGuid) ? $this->getByGuid($identifier) : $this->getById($identifier); - - $nzbpath = ""; - if ($isGuid) - $nzbpath = $site->nzbpath.substr($identifier, 0, 1)."/".$identifier.".nzb.gz"; - elseif ($rel) - $nzbpath = $site->nzbpath.substr($rel["guid"], 0, 1)."/".$rel["guid"].".nzb.gz"; - - if ($nzbpath != "" && file_exists($nzbpath)) - unlink($nzbpath); - - $audiopreviewpath = ""; - if ($isGuid) - $audiopreviewpath = WWW_DIR.'covers/audio/'.$identifier.".mp3"; - elseif ($rel) - $audiopreviewpath = WWW_DIR.'covers/audio/'.$rel["guid"].".mp3"; - - if ($audiopreviewpath && file_exists($audiopreviewpath)) - unlink($audiopreviewpath); - - if ($rel) - { - $nfo->deleteReleaseNfo($rel['ID']); - $rc->deleteCommentsForRelease($rel['ID']); - $users->delCartForRelease($rel['ID']); - $users->delDownloadRequestsForRelease($rel['ID']); - $rf->delete($rel['ID']); - $re->delete($rel['ID']); - $re->deleteFull($rel['ID']); - $ri->delete($rel['guid']); - $db->query(sprintf("delete from releases where id = %d", $rel['ID'])); - } - } - } - public function fastDelete($id, $guid, $site) - { - $db = new DB(); - $nzb = new NZB(); - $ri = new ReleaseImage(); - - - // - // delete from disk. - // - $nzbpath = $nzb->getNZBPath($guid, $site->nzbpath, false); - - if (file_exists($nzbpath)) - unlink($nzbpath); - - $db->query(sprintf("delete releases, releasenfo, releasecomment, usercart, releasefiles, releaseaudio, releasesubs, releasevideo, releaseextrafull - from releases - LEFT OUTER JOIN releasenfo on releasenfo.releaseID = releases.ID - LEFT OUTER JOIN releasecomment on releasecomment.releaseID = releases.ID - LEFT OUTER JOIN usercart on usercart.releaseID = releases.ID - LEFT OUTER JOIN releasefiles on releasefiles.releaseID = releases.ID - LEFT OUTER JOIN releaseaudio on releaseaudio.releaseID = releases.ID - LEFT OUTER JOIN releasesubs on releasesubs.releaseID = releases.ID - LEFT OUTER JOIN releasevideo on releasevideo.releaseID = releases.ID - LEFT OUTER JOIN releaseextrafull on releaseextrafull.releaseID = releases.ID - where releases.ID = %d", $id)); - - $ri->delete($guid); // This deletes a file so not in the query - } - - /** - * Delete a preview associated with a release and update the release to indicate it doesnt have one. - */ - public function deletePreview($guid) - { - $this->updateHasPreview($guid, 0); - $ri = new ReleaseImage(); - $ri->delete($guid); - } - - /** - * Update a release. - */ - public function update($id, $name, $searchname, $fromname, $category, $parts, $grabs, $size, $posteddate, $addeddate, $rageid, $seriesfull, $season, $episode, $imdbid, $anidbid, $tvdbid, $consoleinfoid) - { - $db = new DB(); - - $db->query(sprintf("update releases set name=%s, searchname=%s, fromname=%s, categoryID=%d, totalpart=%d, grabs=%d, size=%s, postdate=%s, adddate=%s, rageID=%d, seriesfull=%s, season=%s, episode=%s, imdbID=%d, anidbID=%d, tvdbID=%d,consoleinfoID=%d where id = %d", - $db->escapeString($name), $db->escapeString($searchname), $db->escapeString($fromname), $category, $parts, $grabs, $db->escapeString($size), $db->escapeString($posteddate), $db->escapeString($addeddate), $rageid, $db->escapeString($seriesfull), $db->escapeString($season), $db->escapeString($episode), $imdbid, $anidbid, $tvdbid, $consoleinfoid, $id)); - } - - /** - * Update multiple releases. - */ - public function updatemulti($guids, $category, $grabs, $rageid, $season, $imdbid) - { - if (!is_array($guids) || sizeof($guids) < 1) - return false; - - $update = array( - 'categoryID'=>(($category == '-1') ? '' : $category), - 'grabs'=>$grabs, - 'rageID'=>$rageid, - 'season'=>$season, - 'imdbID'=>$imdbid - ); - - $db = new DB(); - $updateSql = array(); - foreach($update as $updk=>$updv) { - if ($updv != '') - $updateSql[] = sprintf($updk.'=%s', $db->escapeString($updv)); - } - - if (sizeof($updateSql) < 1) { - //echo 'no field set to be changed'; - return -1; - } - - $updateGuids = array(); - foreach($guids as $guid) { - $updateGuids[] = $db->escapeString($guid); - } - - $sql = sprintf('update releases set '.implode(', ', $updateSql).' where guid in (%s)', implode(', ', $updateGuids)); - return $db->query($sql); - } - - /** - * Update whether a release has a preview. - */ - public function updateHasPreview($guid, $haspreview) - { - $db = new DB(); - $db->query(sprintf("update releases set haspreview = %d where guid = %s", $haspreview, $db->escapeString($guid))); - } - - /** - * Not yet implemented. - */ - public function searchadv($searchname, $filename, $poster, $group, $cat=array(-1), $sizefrom, $sizeto, $offset=0, $limit=1000, $orderby='', $maxage=-1, $excludedcats=array()) - { - return array(); - } - - /** - * Search for releases. - */ - public function search($search, $cat=array(-1), $offset=0, $limit=1000, $orderby='', $maxage=-1, $excludedcats=array(), $grp=array(), $minsize=-1, $maxsize=-1) - { - $s = new Sites(); - $site = $s->get(); - - if ($site->sphinxenabled) - { - $sphinx = new Sphinx(); - $order = $this->getBrowseOrder($orderby); - $results = $sphinx->search($search, $cat, $offset, $limit, $order, $maxage, $excludedcats, $grp, array(), true, $minsize, $maxsize); - if (is_array($results)) - return $results; - } - - // - // Search using MySQL - // - $db = new DB(); - - $catsrch = ""; - $usecatindex = ""; - if (count($cat) > 0 && $cat[0] != -1) - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - $usecatindex = " use index (ix_releases_categoryID) "; - } - - $grpsql = ""; - if (count($grp) > 0) - { - $grpsql = " and ("; - foreach ($grp as $grpname) - { - $grpsql.= sprintf(" groups.name = %s or ", $db->escapeString(str_replace("a.b.", "alt.binaries.", $grpname))); - } - $grpsql.= "1=2 )"; - } - - // - // if the query starts with a ^ it indicates the search is looking for items which start with the term - // still do the fulltext match, but mandate that all items returned must start with the provided word - // - $words = explode(" ", $search); - $searchsql = ""; - $intwordcount = 0; - if (count($words) > 0) - { - foreach ($words as $word) - { - if ($word != "") - { - // - // see if the first word had a caret, which indicates search must start with term - // - if ($intwordcount == 0 && (strpos($word, "^") === 0)) - $searchsql.= sprintf(" and releases.searchname like %s", $db->escapeString(substr($word, 1)."%")); - elseif (substr($word, 0, 2) == '--') - $searchsql.= sprintf(" and releases.searchname not like %s", $db->escapeString("%".substr($word, 2)."%")); - else - $searchsql.= sprintf(" and releases.searchname like %s", $db->escapeString("%".$word."%")); - - $intwordcount++; - } - } - } - - if ($maxage > 0) - $maxage = sprintf(" and postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; - - if ($minsize != -1) - $minsize = sprintf(" and size > %d ", $minsize); - else - $minsize = ""; - - if ($maxsize != -1) - $maxsize = sprintf(" and size < %d ", $maxsize); - else - $maxsize = ""; - - $exccatlist = ""; - if (count($excludedcats) > 0) - $exccatlist = " and releases.categoryID not in (".implode(",", $excludedcats).")"; - - if ($orderby == "") - { - $order[0] = " postdate "; - $order[1] = " desc "; - } - else - $order = $this->getBrowseOrder($orderby); - - $sql = sprintf("select releases.*, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, rn.ID as nfoID, re.releaseID as reID, cp.ID as categoryParentID, pre.ctime, pre.nuketype, coalesce(movieinfo.ID,0) as movieinfoID from releases %s left outer join movieinfo on movieinfo.imdbID = releases.imdbID left outer join releasevideo re on re.releaseID = releases.ID left outer join releasenfo rn on rn.releaseID = releases.ID left outer join groups on groups.ID = releases.groupID left outer join category c on c.ID = releases.categoryID left outer join category cp on cp.ID = c.parentID left outer join predb pre on pre.ID = releases.preID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s %s %s %s order by %s %s limit %d, %d ", $usecatindex, $searchsql, $catsrch, $maxage, $exccatlist, $grpsql, $minsize, $maxsize, $order[0], $order[1], $offset, $limit); - $orderpos = strpos($sql, "order by"); - $wherepos = strpos($sql, "where"); - $sqlcount = "select count(releases.ID) as num from releases ".substr($sql, $wherepos,$orderpos-$wherepos); - - $countres = $db->queryOneRow($sqlcount, true); - $res = $db->query($sql, true); - if (count($res) > 0) - $res[0]["_totalrows"] = $countres["num"]; - - return $res; - } - - /** - * Search for releases by rage id. Used by API/Sickbeard. - */ - public function searchbyRageId($rageId, $series="", $episode="", $offset=0, $limit=100, $name="", $cat=array(-1), $maxage=-1) - { - $s = new Sites(); - $site = $s->get(); - - if ($site->sphinxenabled) - { - $sphinx = new Sphinx(); - $results = $sphinx->searchbyRageId($rageId, $series, $episode, $offset, $limit, $name, $cat, $maxage, array(), true); - if (is_array($results)) - return $results; - } - - $db = new DB(); - - if ($rageId != "-1") - $rageId = sprintf(" and rageID = %d ", $rageId); - else - $rageId = ""; - - if ($series != "") - { - // - // Exclude four digit series, which will be the year 2010 etc - // - if (is_numeric($series) && strlen($series) != 4) - $series = sprintf('S%02d', $series); - - $series = sprintf(" and releases.season = %s", $db->escapeString($series)); - } - if ($episode != "") - { - if (is_numeric($episode)) - $episode = sprintf('E%02d', $episode); - - $episode = sprintf(" and releases.episode like %s", $db->escapeString('%'.$episode.'%')); - } - - // - // if the query starts with a ^ it indicates the search is looking for items which start with the term - // still do the fulltext match, but mandate that all items returned must start with the provided word - // - $words = explode(" ", $name); - $searchsql = ""; - $intwordcount = 0; - if (count($words) > 0) - { - foreach ($words as $word) - { - if ($word != "") - { - // - // see if the first word had a caret, which indicates search must start with term - // - if ($intwordcount == 0 && (strpos($word, "^") === 0)) - $searchsql.= sprintf(" and releases.searchname like %s", $db->escapeString(substr($word, 1)."%")); - elseif (substr($word, 0, 2) == '--') - $searchsql.= sprintf(" and releases.searchname not like %s", $db->escapeString("%".substr($word, 2)."%")); - else - $searchsql.= sprintf(" and releases.searchname like %s", $db->escapeString("%".$word."%")); - - $intwordcount++; - } - } - } - - $catsrch = ""; - $usecatindex = ""; - if (count($cat) > 0 && $cat[0] != -1) - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - $usecatindex = " use index (ix_releases_categoryID) "; - } - - if ($maxage > 0) - $maxage = sprintf(" and postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; - - $sql = sprintf("select releases.*, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, rn.ID as nfoID, re.releaseID as reID from releases %s left outer join category c on c.ID = releases.categoryID left outer join groups on groups.ID = releases.groupID left outer join releasevideo re on re.releaseID = releases.ID left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join category cp on cp.ID = c.parentID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s %s %s order by postdate desc limit %d, %d ", $usecatindex, $rageId, $series, $episode, $searchsql, $catsrch, $maxage, $offset, $limit); - $orderpos = strpos($sql, "order by"); - $wherepos = strpos($sql, "where"); - $sqlcount = "select count(releases.ID) as num from releases ".substr($sql, $wherepos,$orderpos-$wherepos); - - $countres = $db->queryOneRow($sqlcount, true); - $res = $db->query($sql, true); - if (count($res) > 0) - $res[0]["_totalrows"] = $countres["num"]; - - return $res; - } - - /** - * Search for releases by anidb id. Used by API/Sickbeard. - */ - public function searchbyAnidbId($anidbID, $epno='', $offset=0, $limit=100, $name='', $maxage=-1) - { - $s = new Sites(); - $site = $s->get(); - if ($site->sphinxenabled) - { - $sphinx = new Sphinx(); - $results = $sphinx->searchbyAnidbId($anidbID, $epno, $offset, $limit, $name, $maxage, array(), true); - if (is_array($results)) - return $results; - } - - $db = new DB(); - - $anidbID = ($anidbID > -1) ? sprintf(" AND anidbID = %d ", $anidbID) : ''; - - $epno = is_numeric($epno) ? sprintf(" AND releases.episode LIKE '%s' ", $db->escapeString('%'.$epno.'%')) : ''; - - // - // if the query starts with a ^ it indicates the search is looking for items which start with the term - // still do the fulltext match, but mandate that all items returned must start with the provided word - // - $words = explode(" ", $name); - $searchsql = ""; - $intwordcount = 0; - if (count($words) > 0) - { - foreach ($words as $word) - { - if ($word != "") - { - // - // see if the first word had a caret, which indicates search must start with term - // - if ($intwordcount == 0 && (strpos($word, "^") === 0)) - $searchsql.= sprintf(" AND releases.searchname LIKE '%s' ", $db->escapeString(substr($word, 1)."%")); - elseif (substr($word, 0, 2) == '--') - $searchsql.= sprintf(" AND releases.searchname NOT LIKE '%s' ", $db->escapeString("%".substr($word, 2)."%")); - else - $searchsql.= sprintf(" AND releases.searchname LIKE '%s' ", $db->escapeString("%".$word."%")); - - $intwordcount++; - } - } - } - - $maxage = ($maxage > 0) ? sprintf(" and postdate > now() - interval %d day ", $maxage) : ''; - - $sql = sprintf("SELECT releases.*, concat(cp.title, ' > ', c.title) - AS category_name, concat(cp.ID, ',', c.ID) AS category_ids, groups.name AS group_name, rn.ID AS nfoID - FROM releases LEFT OUTER JOIN category c ON c.ID = releases.categoryID LEFT OUTER JOIN groups ON groups.ID = releases.groupID - LEFT OUTER JOIN releasenfo rn ON rn.releaseID = releases.ID and rn.nfo IS NOT NULL LEFT OUTER JOIN category cp ON cp.ID = c.parentID - WHERE releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s ORDER BY postdate desc LIMIT %d, %d ", - $anidbID, $epno, $searchsql, $maxage, $offset, $limit); - $orderpos = strpos($sql, "ORDER BY"); - $wherepos = strpos($sql, "WHERE"); - $sqlcount = "SELECT count(releases.ID) AS num FROM releases ".substr($sql, $wherepos,$orderpos-$wherepos); - - $countres = $db->queryOneRow($sqlcount, true); - $res = $db->query($sql, true); - if (count($res) > 0) - $res[0]["_totalrows"] = $countres["num"]; - - return $res; - } - - /** - * Search for releases by album/artist/musicinfo. Used by API. - */ - public function searchAudio($artist, $album, $label, $track, $year, $genre=array(-1), $offset=0, $limit=100, $cat=array(-1), $maxage=-1) - { - $s = new Sites(); - $site = $s->get(); - if ($site->sphinxenabled) - { - $sphinx = new Sphinx(); - $results = $sphinx->searchAudio($artist, $album, $label, $track, $year, $genre, $offset, $limit, $cat, $maxage, array(), true); - if (is_array($results)) - return $results; - } - - $db = new DB(); - $searchsql = ""; - - if ($artist != "") - $searchsql.= sprintf(" and musicinfo.artist like %s ", $db->escapeString("%".$artist."%")); - if ($album != "") - $searchsql.= sprintf(" and musicinfo.title like %s ", $db->escapeString("%".$album."%")); - if ($label != "") - $searchsql.= sprintf(" and musicinfo.publisher like %s ", $db->escapeString("%".$label."%")); - if ($track != "") - $searchsql.= sprintf(" and musicinfo.tracks like %s ", $db->escapeString("%".$track."%")); - if ($year != "") - $searchsql.= sprintf(" and musicinfo.year = %d ", $year); - - - $catsrch = ""; - $usecatindex = ""; - if (count($cat) > 0 && $cat[0] != -1) - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - $usecatindex = " use index (ix_releases_categoryID) "; - } - - if ($maxage > 0) - $maxage = sprintf(" and postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; - - $genresql = ""; - if (count($genre) > 0 && $genre[0] != -1) - { - $genresql = " and ("; - foreach ($genre as $g) - { - $genresql .= sprintf(" musicinfo.genreID = %d or ", $g); - } - $genresql.= "1=2 )"; - } - - $sql = sprintf("select releases.*, musicinfo.cover as mi_cover, musicinfo.review as mi_review, musicinfo.tracks as mi_tracks, musicinfo.publisher as mi_publisher, musicinfo.title as mi_title, musicinfo.artist as mi_artist, genres.title as music_genrename, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, rn.ID as nfoID from releases %s left outer join musicinfo on musicinfo.ID = releases.musicinfoID left join genres on genres.ID = musicinfo.genreID left outer join groups on groups.ID = releases.groupID left outer join category c on c.ID = releases.categoryID left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join category cp on cp.ID = c.parentID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s order by postdate desc limit %d, %d ", $usecatindex, $searchsql, $catsrch, $maxage, $genresql, $offset, $limit); - $orderpos = strpos($sql, "order by"); - $wherepos = strpos($sql, "where"); - $sqlcount = "select count(releases.ID) as num from releases inner join musicinfo on musicinfo.ID = releases.musicinfoID ".substr($sql, $wherepos,$orderpos-$wherepos); - - $countres = $db->queryOneRow($sqlcount, true); - $res = $db->query($sql, true); - if (count($res) > 0) - $res[0]["_totalrows"] = $countres["num"]; - - return $res; - } - - /** - * Search for releases by author/bookinfo. Used by API. - */ - public function searchBook($author, $title, $offset=0, $limit=100, $maxage=-1) - { - $s = new Sites(); - $site = $s->get(); - if ($site->sphinxenabled) - { - $sphinx = new Sphinx(); - $results = $sphinx->searchBook($author, $title, $offset, $limit, $maxage, array(), true); - if (is_array($results)) - return $results; - } - - $db = new DB(); - $searchsql = ""; - - if ($author != "") - $searchsql.= sprintf(" and bookinfo.author like %s ", $db->escapeString("%".$author."%")); - if ($title != "") - $searchsql.= sprintf(" and bookinfo.title like %s ", $db->escapeString("%".$title."%")); - - if ($maxage > 0) - $maxage = sprintf(" and postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; - - $sql = sprintf("select releases.*, bookinfo.cover as bi_cover, bookinfo.review as bi_review, bookinfo.publisher as bi_publisher, bookinfo.pages as bi_pages, bookinfo.publishdate as bi_publishdate, bookinfo.title as bi_title, bookinfo.author as bi_author, genres.title as book_genrename, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, rn.ID as nfoID from releases left outer join bookinfo on bookinfo.ID = releases.bookinfoID left join genres on genres.ID = bookinfo.genreID left outer join groups on groups.ID = releases.groupID left outer join category c on c.ID = releases.categoryID left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join category cp on cp.ID = c.parentID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s order by postdate desc limit %d, %d ", $searchsql, $maxage, $offset, $limit); - $orderpos = strpos($sql, "order by"); - $wherepos = strpos($sql, "where"); - $sqlcount = "select count(releases.ID) as num from releases inner join bookinfo on bookinfo.ID = releases.bookinfoID ".substr($sql, $wherepos,$orderpos-$wherepos); - - $countres = $db->queryOneRow($sqlcount, true); - $res = $db->query($sql, true); - if (count($res) > 0) - $res[0]["_totalrows"] = $countres["num"]; - - return $res; - } - - /** - * Search for releases by imdbid/movieinfo. Used by API/Couchpotato. - */ - public function searchbyImdbId($imdbId, $offset=0, $limit=100, $name="", $cat=array(-1), $genre="", $maxage=-1) - { - $s = new Sites(); - $site = $s->get(); - if ($site->sphinxenabled) - { - $sphinx = new Sphinx(); - $results = $sphinx->searchbyImdbId($imdbId, $offset, $limit, $name, $cat, $genre, $maxage, array(), true); - if (is_array($results)) - return $results; - } - - $db = new DB(); - - if ($imdbId != "-1" && is_numeric($imdbId)) - { - //pad id with zeros just in case - $imdbId = str_pad($imdbId, 7, "0",STR_PAD_LEFT); - $imdbId = sprintf(" and releases.imdbID = %d ", $imdbId); - } - else - { - $imdbId = ""; - } - - // - // if the query starts with a ^ it indicates the search is looking for items which start with the term - // still do the fulltext match, but mandate that all items returned must start with the provided word - // - $words = explode(" ", $name); - $searchsql = ""; - $intwordcount = 0; - if (count($words) > 0) - { - foreach ($words as $word) - { - if ($word != "") - { - // - // see if the first word had a caret, which indicates search must start with term - // - if ($intwordcount == 0 && (strpos($word, "^") === 0)) - $searchsql.= sprintf(" and releases.searchname like %s", $db->escapeString(substr($word, 1)."%")); - elseif (substr($word, 0, 2) == '--') - $searchsql.= sprintf(" and releases.searchname not like %s", $db->escapeString("%".substr($word, 2)."%")); - else - $searchsql.= sprintf(" and releases.searchname like %s", $db->escapeString("%".$word."%")); - - $intwordcount++; - } - } - } - - $catsrch = ""; - if (count($cat) > 0 && $cat[0] != -1) - { - $catsrch = " and ("; - foreach ($cat as $category) - { - if ($category != -1) - { - $categ = new Category(); - if ($categ->isParent($category)) - { - $children = $categ->getChildren($category); - $chlist = "-99"; - foreach ($children as $child) - $chlist.=", ".$child["ID"]; - - if ($chlist != "-99") - $catsrch .= " releases.categoryID in (".$chlist.") or "; - } - else - { - $catsrch .= sprintf(" releases.categoryID = %d or ", $category); - } - } - } - $catsrch.= "1=2 )"; - } - - if ($maxage > 0) - $maxage = sprintf(" and releases.postdate > now() - interval %d day ", $maxage); - else - $maxage = ""; - - if ($genre != "") - { - $genre = sprintf(" and movieinfo.genre like %s", $db->escapeString("%".$genre."%")); - } - - $sql = sprintf("select releases.*, movieinfo.title as moi_title, movieinfo.tagline as moi_tagline, movieinfo.rating as moi_rating, movieinfo.plot as moi_plot, movieinfo.year as moi_year, movieinfo.genre as moi_genre, movieinfo.director as moi_director, movieinfo.actors as moi_actors, movieinfo.cover as moi_cover, movieinfo.backdrop as moi_backdrop, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name, rn.ID as nfoID from releases left outer join groups on groups.ID = releases.groupID left outer join category c on c.ID = releases.categoryID left outer join releasenfo rn on rn.releaseID = releases.ID and rn.nfo is not null left outer join category cp on cp.ID = c.parentID left outer join movieinfo on releases.imdbID = movieinfo.imdbID where releases.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s %s %s %s order by postdate desc limit %d, %d ", $searchsql, $imdbId, $catsrch, $maxage, $genre, $offset, $limit); - $orderpos = strpos($sql, "order by"); - $wherepos = strpos($sql, "where"); - $sqlcount = "select count(releases.ID) as num from releases left outer join movieinfo on releases.imdbID = movieinfo.imdbID ".substr($sql, $wherepos,$orderpos-$wherepos); - - $countres = $db->queryOneRow($sqlcount, true); - $res = $db->query($sql, true); - if (count($res) > 0) - $res[0]["_totalrows"] = $countres["num"]; - - return $res; - } - - /** - * Return a list of releases with a similar name to that provided. - */ - public function searchSimilar($currentid, $name, $limit=6, $excludedcats=array()) - { - $name = $this->getSimilarName($name); - $results = $this->search($name, array(-1), 0, $limit, '', -1, $excludedcats); - if (!$results) - return $results; - - // - // Get the category for the parent of this release - // - $currRow = $this->getById($currentid); - $cat = new Category(); - $catrow = $cat->getById($currRow["categoryID"]); - $parentCat = $catrow["parentID"]; - - $ret = array(); - foreach ($results as $res) - if ($res["ID"] != $currentid && $res["categoryParentID"] == $parentCat) - $ret[] = $res; - - return $ret; - } - - /** - * Return a similar release name. - */ - public function getSimilarName($name) - { - $words = str_word_count(str_replace(array(".","_"), " ", $name), 2); - $firstwords = array_slice($words, 0, 2); - return implode(' ', $firstwords); - } - - /** - * Retrieve one or more releases by guid. - */ - public function getByGuid($guid) - { - $db = new DB(); - if (is_array($guid)) - { - $tmpguids = array(); - foreach($guid as $g) - $tmpguids[] = $db->escapeString($g); - $gsql = sprintf('guid in (%s)', implode(',',$tmpguids)); - } else { - $gsql = sprintf('guid = %s', $db->escapeString($guid)); - } - $sql = sprintf("select releases.*, musicinfo.cover as mi_cover, musicinfo.review as mi_review, musicinfo.tracks as mi_tracks, musicinfo.publisher as mi_publisher, musicinfo.title as mi_title, musicinfo.artist as mi_artist, music_genre.title as music_genrename, bookinfo.cover as bi_cover, bookinfo.review as bi_review, bookinfo.publisher as bi_publisher, bookinfo.publishdate as bi_publishdate, bookinfo.title as bi_title, bookinfo.author as bi_author, bookinfo.pages as bi_pages, bookinfo.isbn as bi_isbn, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, groups.name as group_name from releases left outer join groups on groups.ID = releases.groupID left outer join category c on c.ID = releases.categoryID left outer join category cp on cp.ID = c.parentID left outer join musicinfo on musicinfo.ID = releases.musicinfoID left outer join bookinfo on bookinfo.ID = releases.bookinfoID left join genres music_genre on music_genre.ID = musicinfo.genreID where %s ", $gsql); - return (is_array($guid)) ? $db->query($sql) : $db->queryOneRow($sql); - } - - /** - * Writes a zip file of an array of release guids directly to the stream - */ - public function getZipped($guids) - { - $s = new Sites(); - $nzb = new NZB; - $site = $s->get(); - $zipfile = new zipfile(); - - foreach ($guids as $guid) - { - $nzbpath = $nzb->getNZBPath($guid, $site->nzbpath); - - if (file_exists($nzbpath)) - { - ob_start(); - @readgzfile($nzbpath); - $nzbfile = ob_get_contents(); - ob_end_clean(); - - $filename = $guid; - $r = $this->getByGuid($guid); - if ($r) - $filename = $r["searchname"]; - - $zipfile->addFile($nzbfile, $filename.".nzb"); - } - } - - return $zipfile->file(); - } - - /** - * Removes an associated tvrage id from all releases using it. - */ - public function removeRageIdFromReleases($rageid) - { - $db = new DB(); - $res = $db->queryOneRow(sprintf("select count(ID) as num from releases where rageID = %d", $rageid)); - $ret = $res["num"]; - $db->query(sprintf("update releases set rageID = -1, seriesfull = null, season = null, episode = null where rageID = %d", $rageid)); - return $ret; - } - - /** - * Removes an associated tvdb id from all releases using it. - */ - public function removeThetvdbIdFromReleases($tvdbID) - { - $db = new DB(); - $res = $db->queryOneRow(sprintf("SELECT count(ID) AS num FROM releases WHERE tvdbID = %d", $tvdbID)); - $ret = $res["num"]; - $res = $db->query(sprintf("UPDATE releases SET tvdbID = -1 where tvdbID = %d", $tvdbID)); - return $ret; - } - - public function removeAnidbIdFromReleases($anidbID) - { - $db = new DB(); - $res = $db->queryOneRow(sprintf("SELECT count(ID) AS num FROM releases WHERE anidbID = %d", $anidbID)); - $ret = $res["num"]; - $db->query(sprintf("UPDATE releases SET anidbID = -1, episode = null, tvtitle = null, tvairdate = null where anidbID = %d", $anidbID)); - return $ret; - } - - public function getById($id) - { - $db = new DB(); - return $db->queryOneRow(sprintf("select releases.*, groups.name as group_name from releases left outer join groups on groups.ID = releases.groupID where releases.ID = %d ", $id)); - } - - public function getReleaseNfo($id, $incnfo=true) - { - $db = new DB(); - $selnfo = ($incnfo) ? ', uncompress(nfo) as nfo' : ''; - return $db->queryOneRow(sprintf("SELECT ID, releaseID".$selnfo." FROM releasenfo where releaseID = %d AND nfo IS NOT NULL", $id)); - } - - public function updateGrab($guid) - { - $db = new DB(); - $db->queryOneRow(sprintf("update releases set grabs = grabs + 1 where guid = %s", $db->escapeString($guid))); - } - - function processReleases() - { - require_once(WWW_DIR."/lib/binaries.php"); - - $db = new DB; - - // - // Get the current datetime again, as using now() in the housekeeping queries prevents the index being used. - // - $currTime_ori = $db->queryOneRow("SELECT NOW() as now"); - - $cat = new Category(); - $nzb = new Nzb(); - $s = new Sites(); - $relreg = new ReleaseRegex(); - $page = new Page(); - $retcount = 0; - - echo $s->getLicense(); - - echo "\n\nStarting release update process (".date("Y-m-d H:i:s").")\n"; - - if (!file_exists($page->site->nzbpath)) - { - echo "Bad or missing nzb directory - ".$page->site->nzbpath; - return -1; - } - - $this->checkRegexesUptoDate($page->site->latestregexurl, $page->site->latestregexrevision, $page->site->newznabID); - - // - // Get all regexes for all groups which are to be applied to new binaries - // in order of how they should be applied - // - $regexrows = $relreg->get(); - echo "Stage 1 : Applying regex to binaries\n"; - foreach ($regexrows as $regexrow) - { - $groupmatch = ""; - - // - // Groups ending in * need to be like matched when getting out binaries for groups and children - // - if (preg_match("/\*$/i", $regexrow["groupname"])) - { - $groupname = substr($regexrow["groupname"], 0, -1); - $resgrps = $db->query(sprintf("select ID from groups where name like %s ", $db->escapeString($groupname."%"))); - foreach ($resgrps as $resgrp) - $groupmatch.=" groupID = ".$resgrp["ID"]." or "; - - $groupmatch.=" 1=2 "; - } - // - // A group name which doesnt end in a * needs an exact match - // - elseif ($regexrow["groupname"] != "") - { - $resgrp = $db->queryOneRow(sprintf("select ID from groups where name = %s ", $db->escapeString($regexrow["groupname"]))); - - // - // if group not found, its a regex for a group we arent indexing. - // - if ($resgrp) - $groupmatch = " groupID = ".$resgrp["ID"]; - else - $groupmatch = " 1=2 " ; - } - // - // No groupname specified (these must be the misc regexes applied to all groups) - // - else - $groupmatch = " 1=1 "; - - // Get out all binaries of STAGE0 for current group - $arrNoPartBinaries = array(); - $resbin = $db->queryDirect(sprintf("SELECT binaries.ID, binaries.name, binaries.date, binaries.totalParts from binaries where (%s) and procstat = %d order by binaries.date asc", $groupmatch, Releases::PROCSTAT_NEW)); - - $db->disableAutoCommit(); - - while ($rowbin = $db->getAssocArray($resbin)) - { - if (preg_match ($regexrow["regex"], $rowbin["name"], $matches)) - { - $matches = array_map("trim", $matches); - - if (isset($matches['reqid']) && (!isset($matches['name']) || empty($matches['name']))) { - $matches['name'] = $matches['reqid']; - } - - // Check that the regex provided the correct parameters - if (!isset($matches['name']) || empty($matches['name'])) - { - continue; - } - - // If theres no number of files data in the subject, put it into a release if it was posted to usenet longer than five hours ago. - if ((!isset($matches['parts']) && strtotime($currTime_ori['now']) - strtotime($rowbin['date']) > 18000) || isset($arrNoPartBinaries[$matches['name']])) - { - // - // Take a copy of the name of this no-part release found. This can be used - // next time round the loop to find parts of this set, but which have not yet reached 3 hours. - // - $arrNoPartBinaries[$matches['name']] = "1"; - $matches['parts'] = "01/01"; - } - - - if (isset($matches['name']) && isset($matches['parts'])) - { - if (strpos($matches['parts'], '/') === false) - { - $matches['parts'] = str_replace(array('-','~',' of '), '/', $matches['parts']); - } - - $regcatid = "null "; - if ($regexrow["categoryID"] != "") - $regcatid = $regexrow["categoryID"]; - //override if regex specifies pc oday but content is some other form of PC or Ebook - if ($regcatid == Category::CAT_PC_0DAY) - { - if ($cat->isMobileAndroid($matches['name'])) - $regcatid = Category::CAT_PC_MOBILEANDROID; - if ($cat->isMobileiOS($matches['name'])) - $regcatid = Category::CAT_PC_MOBILEIOS; - if ($cat->isMobileOther($matches['name'])) - $regcatid = Category::CAT_PC_MOBILEOTHER; - if ($cat->isIso($matches['name'])) - $regcatid = Category::CAT_PC_ISO; - if ($cat->isMac($matches['name'])) - $regcatid = Category::CAT_PC_MAC; - if ($cat->isPcGame($matches['name'])) - $regcatid = Category::CAT_PC_GAMES; - if ($cat->isBookEBook($matches['name'])) - $regcatid = Category::CAT_BOOK_EBOOK; - } - - $reqid = " null "; - if (isset($matches['reqid'])) - $reqid = $db->escapeString($matches['reqid']); - - //check if post is repost - if (preg_match('/(repost\d?|re\-?up)/i', $rowbin['name'], $repost) && !preg_match('/repost|re\-?up/i', $matches['name'])) { - $matches['name'] .= ' '.$repost[1]; - } - - $relparts = explode("/", $matches['parts']); - if(count($relparts) < 2) - # Prevent php index error on next line - $relparts[] = $relparts[0]; - - $sql = sprintf("update binaries set relname = replace(%s, '_', ' '), relpart = %d, reltotalpart = %d, procstat=%d, categoryID=%s, regexID=%d, reqID=%s where ID = %d", - $db->escapeString($matches['name']), $relparts[0], (isset($relparts[1]) ? $relparts[1] : $relparts[0]), Releases::PROCSTAT_TITLEMATCHED, $regcatid, $regexrow["ID"], $reqid, $rowbin["ID"] ); - $db->query($sql); - } - } - $db->commit(false); - } - - } - $db->commit(); //re-enables autocommit - - - // - // Move all binaries from releases which have the correct number of files on to the next stage. - // - echo "Stage 2 : Marking binaries where all parts are available\n"; - $result = $db->queryDirect(sprintf("SELECT relname, SUM(reltotalpart) AS reltotalpart, groupID, reqID, fromname, SUM(num) AS num, coalesce(g.minfilestoformrelease, s.minfilestoformrelease) as minfilestoformrelease FROM ( SELECT relname, reltotalpart, groupID, reqID, fromname, COUNT(ID) AS num FROM binaries WHERE procstat = %s GROUP BY relname, reltotalpart, groupID, reqID, fromname ORDER BY NULL ) x left outer join groups g on g.ID = x.groupID inner join ( select value as minfilestoformrelease from site where setting = 'minfilestoformrelease' ) s GROUP BY relname, groupID, reqID, fromname, minfilestoformrelease ORDER BY NULL", Releases::PROCSTAT_TITLEMATCHED)); - - $db->disableAutoCommit(); - while ($row = $db->getAssocArray($result)) - { - $retcount ++; - - // - // Less than the site permitted number of files in a release. Dont discard it, as it may - // be part of a set being uploaded. - // - if ($row["num"] < $row["minfilestoformrelease"]) - { - //echo "Number of files in release ".$row["relname"]." less than site/group setting (".$row['num']."/".$row["minfilestoformrelease"].")\n"; - - $db->query(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname = %s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]) )); - } - - // - // There are the same or more files in our release than the number of files specified - // in the message subject so go ahead and make a release - // - elseif ($row["num"] >= $row["reltotalpart"]) - { - - // Check that the binary is complete - $binlist = $db->query(sprintf("SELECT binaries.ID, totalParts, date, COUNT(DISTINCT parts.messageID) AS num FROM binaries, parts WHERE binaries.ID=parts.binaryID AND binaries.relname = %s AND binaries.procstat = %d AND binaries.groupID = %d AND binaries.fromname = %s GROUP BY binaries.ID ORDER BY NULL", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]) )); - - $incomplete = false; - foreach ($binlist as $rowbin) - { - if ($rowbin['num'] < $rowbin['totalParts']) - { - // Allow to binary to release if posted to usenet longer than four hours ago and we still don't have all the parts - if (!(strtotime($currTime_ori['now']) - strtotime($rowbin['date']) > 14400)) - { - $incomplete = true; - break; - } - } - } - - if ($incomplete) - { - //$db->query(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname = %s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]) )); - } - - // - // Right number of files, but see if the binary is a allfilled/reqid post, in which case it needs its name looked up - // - elseif ($row['reqID'] !='' && $page->site->reqidurl != "") - { - // - // Try and get the name using the group - // - $binGroup = $db->queryOneRow(sprintf("SELECT name FROM groups WHERE ID = %d", $row["groupID"])); - $newtitle = $this->getReleaseNameForReqId($page->site->reqidurl, $page->site->newznabID, $binGroup["name"], $row["reqID"]); - - // - // if the feed/group wasnt supported by the scraper, then just use the release name as the title. - // - if ($newtitle == "no feed") - { - $newtitle = $row["relname"]; - //echo "Group not supported\n"; - } - - // - // Valid release with right number of files and title now, so move it on - // - if ($newtitle != "") - { - $db->query(sprintf("update binaries set relname = %s, procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", - $db->escapeString($newtitle), Releases::PROCSTAT_READYTORELEASE, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); - } - else - { - // - // Item not found, if the binary was added to the index yages ago, then give up. - // - $maxaddeddate = $db->queryOneRow(sprintf("SELECT NOW() as now, MAX(dateadded) as dateadded FROM binaries WHERE relname = %s and procstat = %d and groupID = %d and fromname=%s", - $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); - - // - // If added to the index over 48 hours ago, give up trying to determine the title - // - if (strtotime($maxaddeddate['now']) - strtotime($maxaddeddate['dateadded']) > (60*60*48)) - { - $db->query(sprintf("update binaries set procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", - Releases::PROCSTAT_NOREQIDNAMELOOKUPFOUND, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); - } - } - } - else - { - $db->query(sprintf("update binaries set procstat=%d where relname = %s and procstat = %d and groupID = %d and fromname=%s", - Releases::PROCSTAT_READYTORELEASE, $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]))); - } - } - - // - // Theres less than the expected number of files, so update the attempts and move on. - // - else - { - //echo "Incorrect number of files for ".$row["relname"]." (".$row["num"]."/".$row["reltotalpart"].")\n"; - - $db->query(sprintf("update binaries set procattempts = procattempts + 1 where relname = %s and procstat = %d and groupID = %d and fromname=%s", $db->escapeString($row["relname"]), Releases::PROCSTAT_TITLEMATCHED, $row["groupID"], $db->escapeString($row["fromname"]) )); - } - if ($retcount % 100 == 0) - echo "Stage 2 : Processed ".$retcount." binaries\n"; - if ($retcount % $db->getBatchSize() == 0) - $db->commit(false); - } - $db->commit(); - - $retcount=$nfocount=0; - - echo "Stage 3 : Creating releases from complete binaries\n"; - // - // Get out all distinct relname, group from binaries of STAGE2 - // - $result = $db->queryDirect(sprintf("SELECT relname, groupID, g.name as group_name, fromname, count(binaries.ID) as parts from binaries inner join groups g on g.ID = binaries.groupID where procstat = %d and relname is not null group by relname, g.name, groupID, fromname ORDER BY COUNT(binaries.ID) desc", Releases::PROCSTAT_READYTORELEASE)); - while ($row = $db->getAssocArray($result)) - { - // - // Get the last post date and the poster name from the binary - // - $bindata = $db->queryOneRow(sprintf("select fromname, MAX(date) as date from binaries where relname = %s and procstat = %d and groupID = %d and fromname = %s group by fromname order by null", - $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"]) )); - - // - // Get all releases with the same name with a usenet posted date in a +1-1 date range. - // - $relDupes = $db->query(sprintf("select ID from releases where searchname = %s and ( date_sub(%s, interval 1 day) < postdate AND date_add(%s, interval 1 day) > postdate )", - $db->escapeString($this->cleanReleaseName($row["relname"])), $db->escapeString($bindata["date"]), $db->escapeString($bindata["date"]))); - if (count($relDupes) > 0) - { - $db->query(sprintf("update binaries set procstat = %d where relname = %s and procstat = %d and groupID = %d and fromname=%s ", - Releases::PROCSTAT_DUPLICATE, $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"]))); - continue; - } - - // - // Get some attribs of this release - // - $regexAppliedCategoryID = ""; - $regexIDused = ""; - $reqIDused = ""; - $binSizeId = $db->queryOneRow(sprintf("select ID, categoryID, regexID, reqID, totalParts from binaries use index (ix_binary_relname) where relname = %s and procstat = %d and groupID = %d and fromname=%s", - $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"]) )); - if ($binSizeId) - { - // - // Get categoryID if one has been allocated to this - // - if ($binSizeId["categoryID"] != "") - $regexAppliedCategoryID = $binSizeId["categoryID"]; - // - // Get RegexID if one has been allocated to this - // - if ($binSizeId["regexID"] != "") - $regexIDused = $binSizeId["regexID"]; - // - // Get requestID if one has been allocated to this - // - if ($binSizeId["reqID"] != "") - $reqIDused = $binSizeId["reqID"]; - - } - - // - // Insert the release - // - $relguid = md5(uniqid()); - if ($regexAppliedCategoryID == "") - $catId = $cat->determineCategory($row["group_name"], $row["relname"]); - else - $catId = $regexAppliedCategoryID; - - if ($regexIDused == "") - $regexID = " null "; - else - $regexID = $regexIDused; - - if ($reqIDused == "") - $reqID = " null "; - else - $reqID = $db->escapeString($reqIDused); - - //Clean release name - $cleanRelName = $this->cleanReleaseName($row['relname']); - - $relid = $db->queryInsert(sprintf("insert into releases (name, searchname, totalpart, groupID, adddate, guid, categoryID, regexID, rageID, postdate, fromname, size, reqID, passwordstatus, completion, haspreview) values (%s, %s, %d, %d, now(), %s, %d, %d, -1, %s, %s, 0, %s, %d, 100, %d)", - $db->escapeString($cleanRelName), $db->escapeString($cleanRelName), $row["parts"], $row["groupID"], $db->escapeString($relguid), $catId, $regexID, $db->escapeString($bindata["date"]), $db->escapeString($bindata["fromname"]), $reqID, ($page->site->checkpasswordedrar > 0 ? -1 : 0), -1)); - echo "Stage 3 : Added release ".$cleanRelName."\n"; - - // - // Tag every binary for this release with its parent release id - // remove the release name from the binary as its no longer required - // - $db->query(sprintf("update binaries set procstat = %d, releaseID = %d where relname = %s and procstat = %d and groupID = %d and fromname=%s", - Releases::PROCSTAT_RELEASED, $relid, $db->escapeString($row["relname"]), Releases::PROCSTAT_READYTORELEASE, $row["groupID"], $db->escapeString($row["fromname"]))); - - // - // Write the nzb to disk - // - $nzbfile = $nzb->getNZBPath($relguid, $page->site->nzbpath, true); - $nzb->writeNZBforReleaseId($relid, $relguid, $cleanRelName, $catId, $nzbfile); - - $nzbInfo = new nzbInfo; - - // - // If nzb successfully written, then load it and get size completion from it - // - if (!$nzbInfo->loadFromFile($nzbfile)) - { - echo "Stage 3 : Failed to write nzb file (bad perms?) ".$nzbfile."\n"; - - // - // Remove the release and remark the binaries for processing again. - // - $this->delete($relid); - } - else - { - $db->query(sprintf("update releases set totalpart = %d, size = %s, completion = %d, GID=%s where ID = %d", $nzbInfo->filecount, $nzbInfo->filesize, $nzbInfo->completion, $db->escapeString($nzbInfo->gid), $relid )); - - //Increment new release count - $retcount ++; - } - } - - echo "Stage 4 : Finished processing nfos\n"; - - // - // Delete any releases under the minimum completion percent. - // - if($page->site->completionpercent != 0) - { - echo "Stage 5 : Deleting releases less than ".$page->site->completionpercent." complete\n"; - $result = $db->query(sprintf("select ID from releases where completion > 0 and completion < %d", $page->site->completionpercent)); - foreach ($result as $row) - $this->delete($row["ID"]); - } - - // - // Delete releases whos minsize is less than the site or group minimum - // - $result = $db->query("select releases.ID from releases left outer join (SELECT g.ID, coalesce(g.minsizetoformrelease, s.minsizetoformrelease) as minsizetoformrelease FROM groups g inner join ( select value as minsizetoformrelease from site where setting = 'minsizetoformrelease' ) s ) x on x.ID = releases.groupID where minsizetoformrelease != 0 and releases.size < minsizetoformrelease"); - if (count($result) > 0) - { - echo "Stage 5 : Deleting ".count($result)." release(s) where size is smaller than minsize for site/group\n"; - foreach ($result as $row) - $this->delete($row["ID"]); - } - - $result = $db->query("select releases.ID, name, categoryID, size FROM releases JOIN ( - select - catc.ID, - case when catc.minsizetoformrelease = 0 then catp.minsizetoformrelease else catc.minsizetoformrelease end as minsizetoformrelease, - case when catc.maxsizetoformrelease = 0 then catp.maxsizetoformrelease else catc.maxsizetoformrelease end as maxsizetoformrelease - from category catp join category catc on catc.parentID = catp.ID - where (catc.minsizetoformrelease != 0 or catc.maxsizetoformrelease != 0) or (catp.minsizetoformrelease != 0 or catp.maxsizetoformrelease != 0) - ) x on x.ID = releases.categoryID - where - (size < minsizetoformrelease and minsizetoformrelease != 0) or - (size > maxsizetoformrelease and maxsizetoformrelease != 0)"); - - if(count($result) > 0) - { - echo "Stage 5 : Deleting release(s) not matching category min/max size ...\n"; - foreach ($result as $r){ - $this->delete($r['ID']); - } - } - - echo "Stage 5 : Post processing started\n"; - $postprocess = new PostProcess(true); - $postprocess->processAll(); - - // - // aggregate the releasefiles upto the releases. - // - echo "Stage 6 : Aggregating Files\n"; - $db->query("UPDATE releases INNER JOIN (SELECT releaseID, COUNT(ID) AS num FROM releasefiles GROUP BY releaseID) b ON b.releaseID = releases.ID and releases.rarinnerfilecount = 0 SET rarinnerfilecount = b.num"); - - // Remove the binaries and parts used to form releases, or that are duplicates. - // - if ($page->site->partsdeletechunks > 0) - { - // - // Remove the binaries and parts used to form releases, or that are duplicates. - // - echo "Stage 7 : Chunk deleting unused binaries and parts"; - $query=sprintf("SELECT parts.ID as partsID,binaries.ID as binariesID - FROM parts - LEFT JOIN binaries ON binaries.ID = parts.binaryID - WHERE binaries.procstat IN (%d,%d) - OR binaries.dateadded < %s - INTERVAL %d HOUR LIMIT 0,%d", - Releases::PROCSTAT_RELEASED, Releases::PROCSTAT_DUPLICATE, - $db->escapeString($currTime_ori["now"]), ceil($page->site->rawretentiondays*24), - $page->site->partsdeletechunks); - - $cc=0; - $done=false; - while(!$done) - { - $dd=$cc; - $result=$db->query($query); - $pID=array();$bID=array(); - foreach ($result as $row) - { - $pID[]=$row['partsID']; - $bID[]=$row['binariesID']; - } - $pID='('.implode(',',$pID).')'; - $bID='('.implode(',',$bID).')'; - $db->query("DELETE FROM parts WHERE ID IN {$pID}"); - $fr=$db->getAffectedRows(); - if($fr>0) - { - $cc+=$fr; - $db->query("DELETE FROM binaries WHERE ID IN {$bID}"); - $cc+=$db->getAffectedRows(); - } - unset($pID);unset($bID); - if($cc==$dd) - { - $done=true; - } - echo ($cc % 10000 ? '.':''); - } - echo "\nStage 7 : Complete - ".$cc." rows affected\n"; - } - else - { - echo "Stage 7 : Deleting unused binaries and parts\n"; - $db->query(sprintf("DELETE parts, binaries - FROM parts - LEFT JOIN binaries ON binaries.ID = parts.binaryID - WHERE binaries.procstat IN (%d, %d) - OR binaries.dateadded < %s - INTERVAL %d HOUR", Releases::PROCSTAT_RELEASED, Releases::PROCSTAT_DUPLICATE, $db->escapeString($currTime_ori["now"]), ceil($page->site->rawretentiondays*24))); - } - - // - // User/Request housekeeping, should ideally move this to its own section, but it needs to be done automatically. - // - $users = new Users; - $users->pruneRequestHistory($page->site->userdownloadpurgedays); - - echo "Done : Added ". $retcount." releases\n\n"; - - return $retcount; - } - - public function cleanReleaseName($relname) - { - $cleanArr = array('#', '@', '$', '%', '^', '§', '¨', '©', 'Ö'); - - $relname = str_replace($cleanArr, '', $relname); - $relname = str_replace('_', ' ', $relname); - - return $relname; - } - - public function getReleaseNameForReqId($url, $nnid, $groupname, $reqid) - { - if ($reqid == " null " || $reqid == "0" || $reqid == "") - return ""; - - $url = str_ireplace("[GROUP]", urlencode($groupname), $url); - $url = str_ireplace("[REQID]", urlencode($reqid), $url); - - if ($nnid != "") - { - $url = $url."&newznabID=".$nnid; - } - - $xml = getUrl($url); - - if ($xml === false || preg_match('/no feed/i', $xml)) - return "no feed"; - else - { - if ($xml != "") - { - $xmlObj = @simplexml_load_string($xml); - $arrXml = objectsIntoArray($xmlObj); - - if (isset($arrXml["item"]) && is_array($arrXml["item"]) && is_array($arrXml["item"]["@attributes"])) - { - return $arrXml["item"]["@attributes"]["title"]; - } - } - } - return ""; - } - - public function checkRegexesUptoDate($url, $rev, $nnid) - { - if ($url != "") - { - if ($nnid != "") - $nnid = "?newznabID=".$nnid."&rev=".$rev; - - $regfile = getUrl($url.$nnid, "get", "", "gzip"); - if ($regfile !== false && $regfile != "") - { - /*$Rev: 728 $*/ - if (preg_match('/\/\*\$Rev: (\d{3,4})/i', $regfile, $matches)) - { - $serverrev = intval($matches[1]); - if ($serverrev > $rev) - { - $db = new DB(); - $site = new Sites; - - $queries = explode(";", $regfile); - $queries = array_map("trim", $queries); - foreach($queries as $q) { - if ( $q ) { - $db->query($q); - } - } - - $site->updateLatestRegexRevision($serverrev); - echo "Updated regexes to revision ".$serverrev."\n"; - } - else - { - echo "Using latest regex revision ".$rev."\n"; - } - } - else - { - echo "Error Processing Regex File\n"; - } - } - else - { - echo "Error Regex File Does Not Exist or Unable to Connect\n"; - } - } - } - - public function getTopDownloads() - { - $db = new DB(); - return $db->query("SELECT ID, searchname, guid, adddate, grabs FROM releases - where grabs > 0 - ORDER BY grabs DESC - LIMIT 10"); - } - - public function getTopComments() - { - $db = new DB(); - return $db->query("SELECT ID, guid, searchname, adddate, comments FROM releases - where comments > 0 - ORDER BY comments DESC - LIMIT 10"); - } - - public function getRecentlyAdded() - { - $db = new DB(); - return $db->query("SELECT concat(cp.title, ' > ', category.title) as title, COUNT(*) AS count -FROM category -left outer join category cp on cp.ID = category.parentID -INNER JOIN releases ON releases.categoryID = category.ID -WHERE releases.adddate > NOW() - INTERVAL 1 WEEK -GROUP BY concat(cp.title, ' > ', category.title) -ORDER BY COUNT(*) DESC"); - } - -} diff --git a/test/fixReleaseNames.php b/test/fixReleaseNames.php index e33f327b3..3d8b0b1bf 100755 --- a/test/fixReleaseNames.php +++ b/test/fixReleaseNames.php @@ -13,6 +13,7 @@ require_once(dirname(__FILE__)."/../bin/config.php"); require_once("namefixer.php"); require_once("prehash.php"); +require_once("functions.php"); $n = "\n"; diff --git a/test/namecleaner.php b/test/namecleaner.php index 221c8355c..f9a19d905 100755 --- a/test/namecleaner.php +++ b/test/namecleaner.php @@ -2,6 +2,7 @@ require_once(dirname(__FILE__)."/../bin/config.php"); require_once(WWW_DIR."lib/groups.php"); require_once("prehash.php"); +require_once("functions.php"); diff --git a/test/namefixer.php b/test/namefixer.php index a06e77138..1408255fe 100755 --- a/test/namefixer.php +++ b/test/namefixer.php @@ -4,6 +4,7 @@ require_once(WWW_DIR. "lib/framework/db.php"); require_once(WWW_DIR. "lib/category.php"); require_once(WWW_DIR. "lib/groups.php"); require_once("namecleaner.php"); +require_once("functions.php"); //This script is adapted from nZEDb /* Values of relnamestatus: diff --git a/test/prehash.php b/test/prehash.php index 56e2afcaa..2c6ea40b4 100755 --- a/test/prehash.php +++ b/test/prehash.php @@ -5,6 +5,7 @@ require_once(WWW_DIR."lib/category.php"); require_once(WWW_DIR."lib/groups.php"); require_once(WWW_DIR."lib/nfo.php"); require_once(WWW_DIR."lib/site.php"); +require_once("functions.php"); /* * Class for inserting names/categories/md5 etc from predb sources into the DB, also for matching names on files / subjects. diff --git a/test/removeCrapReleases.php b/test/removeCrapReleases.php index 2316c9d70..5c8746552 100755 --- a/test/removeCrapReleases.php +++ b/test/removeCrapReleases.php @@ -8,6 +8,7 @@ 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/site.php"); +require_once("functions.php"); if (!isset($argv[1]) && !isset($argv[2])) {