Esempio n. 1
0
 /**
  * Function for searching on the site (by subject, searchname or advanced).
  *
  * @param string $searchName
  * @param string $usenetName
  * @param string $posterName
  * @param string $groupName
  * @param int    $sizeFrom
  * @param int    $sizeTo
  * @param int    $hasNfo
  * @param int    $hasComments
  * @param int    $daysNew
  * @param int    $daysOld
  * @param int    $offset
  * @param int    $limit
  * @param string $orderBy
  * @param int    $maxAge
  * @param integer[] $excludedCats
  * @param string $type
  * @param array  $cat
  *
  * @return array
  */
 public function search($searchName, $usenetName, $posterName, $groupName, $sizeFrom, $sizeTo, $hasNfo, $hasComments, $daysNew, $daysOld, $offset = 0, $limit = 1000, $orderBy = '', $maxAge = -1, $excludedCats = [], $type = 'basic', $cat = [-1])
 {
     $sizeRange = [1 => 1, 2 => 2.5, 3 => 5, 4 => 10, 5 => 20, 6 => 30, 7 => 40, 8 => 80, 9 => 160, 10 => 320, 11 => 640];
     if ($orderBy == '') {
         $orderBy = [];
         $orderBy[0] = 'postdate ';
         $orderBy[1] = 'desc ';
     } else {
         $orderBy = $this->getBrowseOrder($orderBy);
     }
     $searchOptions = [];
     if ($searchName != -1) {
         $searchOptions['searchname'] = $searchName;
     }
     if ($usenetName != -1) {
         $searchOptions['name'] = $usenetName;
     }
     if ($posterName != -1) {
         $searchOptions['fromname'] = $posterName;
     }
     $whereSql = sprintf("%s\n\t\t\tWHERE r.passwordstatus %s AND r.nzbstatus = %d %s %s %s %s %s %s %s %s %s %s %s", $this->releaseSearch->getFullTextJoinString(), $this->showPasswords, Enzebe::NZB_ADDED, $maxAge > 0 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $maxAge) : '', $groupName != -1 ? sprintf(' AND r.groupid = %d ', $this->groups->getIDByName($groupName)) : '', array_key_exists($sizeFrom, $sizeRange) ? ' AND r.size > ' . (string) (104857600 * (int) $sizeRange[$sizeFrom]) . ' ' : '', array_key_exists($sizeTo, $sizeRange) ? ' AND r.size < ' . (string) (104857600 * (int) $sizeRange[$sizeTo]) . ' ' : '', $hasNfo != 0 ? ' AND r.nfostatus = 1 ' : '', $hasComments != 0 ? ' AND r.comments > 0 ' : '', $type !== 'advanced' ? $this->categorySQL($cat) : ($cat[0] != '-1' ? sprintf(' AND (r.categoryid = %d) ', $cat[0]) : ''), $daysNew != -1 ? sprintf(' AND r.postdate < (NOW() - INTERVAL %d DAY) ', $daysNew) : '', $daysOld != -1 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $daysOld) : '', count($excludedCats) > 0 ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : '', count($searchOptions) > 0 ? $this->releaseSearch->getSearchSQL($searchOptions) : '');
     $baseSql = sprintf("SELECT r.*,\n\t\t\t\tCONCAT(cp.title, ' > ', c.title) AS category_name,\n\t\t\t\tCONCAT(cp.id, ',', c.id) AS category_ids,\n\t\t\t\tgroups.name AS group_name,\n\t\t\t\trn.id AS nfoid,\n\t\t\t\tre.releaseid AS reid,\n\t\t\t\tcp.id AS categoryparentid\n\t\t\tFROM releases r\n\t\t\tLEFT OUTER JOIN releasevideo re ON re.releaseid = r.id\n\t\t\tLEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id\n\t\t\tINNER JOIN groups ON groups.id = r.groupid\n\t\t\tINNER JOIN category c ON c.id = r.categoryid\n\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t%s", $whereSql);
     $sql = sprintf("SELECT * FROM (\n\t\t\t\t%s\n\t\t\t) r\n\t\t\tORDER BY r.%s %s\n\t\t\tLIMIT %d OFFSET %d", $baseSql, $orderBy[0], $orderBy[1], $limit, $offset);
     $releases = $this->pdo->query($sql);
     if ($releases && count($releases)) {
         $releases[0]['_totalrows'] = $this->getPagerCount($baseSql);
     }
     return $releases;
 }
Esempio n. 2
0
 /**
  * @param int    $imDbId
  * @param int    $offset
  * @param int    $limit
  * @param string $name
  * @param array  $cat
  * @param int    $maxAge
  *
  * @return array
  */
 public function searchbyImdbId($imDbId, $offset = 0, $limit = 100, $name = '', $cat = [-1], $maxAge = -1)
 {
     $baseSql = sprintf("%s\n\t\t\tWHERE r.categoryid BETWEEN 2000 AND 2999\n\t\t\tAND nzbstatus = 1\n\t\t\tAND r.passwordstatus <= %d\n\t\t\t%s %s %s %s", $name !== '' ? $this->releaseSearch->getFullTextJoinString() : '', $this->showPasswords(), $name !== '' ? $this->releaseSearch->getSearchSQL(['searchname' => $name]) : '', $imDbId != '-1' && is_numeric($imDbId) ? sprintf(' AND imdbid = %d ', str_pad($imDbId, 7, '0', STR_PAD_LEFT)) : '', $this->categorySQL($cat), $maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '');
     $sql = sprintf("SELECT SQL_CALC_FOUND_ROWS r.*,\n\t\t\t\tconcat(cp.title, ' > ', c.title) AS category_name,\n\t\t\t\tCONCAT(cp.id, ',', c.id) AS category_ids,\n\t\t\t\tg.name AS group_name,\n\t\t\t\trn.id AS nfoid\n\t\t\tFROM releases r\n\t\t\tINNER JOIN groups g ON g.id = r.group_id\n\t\t\tINNER JOIN category c ON c.id = r.categoryid\n\t\t\tLEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.nfo IS NOT NULL\n\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t%s\n\t\t\tORDER BY postdate DESC\n\t\t\tLIMIT %d OFFSET %d", $baseSql, $limit, $offset);
     $releases = $this->pdo->query($sql);
     $releases[0]['_totalrows'] = $this->pdo->get_Found_Rows();
     return $releases;
 }