Exemplo n.º 1
0
 public function updateMovie($uid, $imdbid, $catid = array())
 {
     $db = new Settings();
     $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null";
     $sql = sprintf("update usermovies set categoryid = %s where userid = %d and imdbid = %d", $catid, $uid, $imdbid);
     $db->queryExec($sql);
 }
Exemplo n.º 2
0
function categorizeRelease($update = true, $where, $echooutput = false)
{
    $pdo = new Settings();
    $cat = new Categorize();
    $consoletools = new consoleTools();
    $relcount = $chgcount = 0;
    $c = new ColorCLI();
    echo $c->primary("SELECT id, searchname, groupid, categoryid FROM releases " . $where);
    $resrel = $pdo->queryDirect("SELECT id, searchname, groupid, categoryid FROM releases " . $where);
    $total = $resrel->rowCount();
    if ($total > 0) {
        foreach ($resrel as $rowrel) {
            $catId = $cat->determineCategory($rowrel['groupid'], $rowrel['searchname']);
            if ($rowrel['categoryid'] != $catId) {
                if ($update === true) {
                    $pdo->queryExec(sprintf("\n\t\t\t\t\t\t\tUPDATE releases\n\t\t\t\t\t\t\tSET iscategorized = 1,\n\t\t\t\t\t\t\t\trageid = -1,\n\t\t\t\t\t\t\t\tseriesfull = NULL,\n\t\t\t\t\t\t\t\tseason = NULL,\n\t\t\t\t\t\t\t\tepisode = NULL,\n\t\t\t\t\t\t\t\ttvtitle = NULL,\n\t\t\t\t\t\t\t\ttvairdate = NULL,\n\t\t\t\t\t\t\t\timdbid = NULL,\n\t\t\t\t\t\t\t\tmusicinfoid = NULL,\n\t\t\t\t\t\t\t\tconsoleinfoid = NULL,\n\t\t\t\t\t\t\t\tgamesinfo_id = 0,\n\t\t\t\t\t\t\t\txxxinfo_id = 0,\n\t\t\t\t\t\t\t\tbookinfoid = NULL,\n\t\t\t\t\t\t\t\tanidbid = NULL,\n\t\t\t\t\t\t\t\tcategoryid = %d\n\t\t\t\t\t\t\tWHERE id = %d", $catId, $rowrel['id']));
                }
                $chgcount++;
            }
            $relcount++;
            if ($echooutput) {
                $consoletools->overWritePrimary("Re-Categorized: [" . number_format($chgcount) . "] " . $consoletools->percentString($relcount, $total));
            }
        }
    }
    if ($echooutput !== false && $relcount > 0) {
        echo "\n";
    }
    return $chgcount;
}
Exemplo n.º 3
0
function releases_rt()
{
    $pdo = new Settings();
    $rows = $pdo->queryExec('SELECT id, guid, name, searchname, fromname FROM releases');
    if ($rows !== false && $rows->rowCount()) {
        $sphinx = new \SphinxSearch();
        $total = $rows->rowCount();
        $string = 'REPLACE INTO releases_rt (id, guid, name, searchname, fromname) VALUES ';
        $tempString = '';
        $i = 0;
        echo '[Starting to populate sphinx RT indexes with ' . $total . ' releases.] ';
        foreach ($rows as $row) {
            $i++;
            $tempString .= sprintf('(%d, %s, %s, %s, %s),', $row['id'], $sphinx->sphinxQL->escapeString($row['guid']), $sphinx->sphinxQL->escapeString($row['name']), $sphinx->sphinxQL->escapeString($row['searchname']), $sphinx->sphinxQL->escapeString($row['fromname']));
            if ($i === 1000 || $i >= $total) {
                $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ','));
                $tempString = '';
                $total -= $i;
                $i = 0;
                echo '.';
            }
        }
        echo ' [Done.]' . PHP_EOL;
    } else {
        echo 'No releases in your DB or an error occurred. This will need to be resolved before you can use the search.' . PHP_EOL;
    }
}
Exemplo n.º 4
0
    /**
     * Update Sphinx Relases index for given releaseid.
     *
     * @param int $releaseID
     * @param \newznab\db\Settings $pdo
     */
    public function updateRelease($releaseID, Settings $pdo)
    {
        if (!is_null($this->sphinxQL)) {
            $new = $pdo->queryOneRow(sprintf('
							SELECT r.id, r.name, r.searchname, r.fromname, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
							FROM releases r
							LEFT JOIN releasefiles rf ON (r.id=rf.releaseid)
							WHERE r.id = %d
							GROUP BY r.id LIMIT 1', $releaseID));
            if ($new !== false) {
                $this->insertRelease($new);
            }
        }
    }
Exemplo n.º 5
0
    /**
     * Fetch a comment and insert it.
     *
     * @param string $messageID Message-ID for the article.
     * @param string $siteID    id of the site.
     *
     * @return bool
     */
    protected function insertNewComment(&$messageID, &$siteID)
    {
        // Get the article body.
        $body = $this->nntp->getMessages(self::group, $messageID);
        // Check if there's an error.
        if ($this->nntp->isError($body)) {
            return false;
        }
        // Decompress the body.
        $body = @gzinflate($body);
        if ($body === false) {
            return false;
        }
        // JSON Decode the body.
        $body = json_decode($body, true);
        if ($body === false) {
            return false;
        }
        // Just in case.
        if (!isset($body['USER']) || !isset($body['SID']) || !isset($body['RID']) || !isset($body['TIME']) | !isset($body['BODY'])) {
            return false;
        }
        $cid = md5($body['SID'] . $body['USER'] . $body['TIME'] . $siteID);
        // Insert the comment.
        if ($this->pdo->queryExec(sprintf('
				INSERT IGNORE INTO releasecomment
				(text, createddate, issynced, shareid, cid, gid, nzb_guid, siteid, username, userid, releaseid, shared, host, sourceID)
				VALUES (%s, %s, 1, %s, %s, %s, %s, %s, %s, 0, 0, 2, "", 999)', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $this->pdo->escapeString($cid), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($siteID), $this->pdo->escapeString(substr($body['USER'], 0, 3) === 'sn-' ? 'SH_ANON' : 'SH_' . $body['USER'])))) {
            return true;
        }
        return false;
    }
Exemplo n.º 6
0
    public function processGamesReleases()
    {
        $res = $this->pdo->queryDirect(sprintf('
				SELECT searchname, id
				FROM releases
				WHERE nzbstatus = 1 %s
				AND gamesinfo_id = 0
				AND categoryid = 4050
				ORDER BY postdate DESC
				LIMIT %d', $this->renamed, $this->gameQty));
        if ($res instanceof \Traversable && $res->rowCount() > 0) {
            if ($this->echoOutput) {
                $this->pdo->log->doEcho($this->pdo->log->header("Processing " . $res->rowCount() . ' games release(s).'));
            }
            foreach ($res as $arr) {
                // Reset maxhitrequest
                $this->maxHitRequest = false;
                $startTime = microtime(true);
                $usedgb = false;
                $gameInfo = $this->parseTitle($arr['searchname']);
                if ($gameInfo !== false) {
                    if ($this->echoOutput) {
                        $this->pdo->log->doEcho($this->pdo->log->headerOver('Looking up: ') . $this->pdo->log->primary($gameInfo['title'] . ' (PC)'));
                    }
                    // Check for existing games entry.
                    $gameCheck = $this->getGamesInfoByName($gameInfo['title']);
                    if ($gameCheck === false) {
                        $gameId = $this->updateGamesInfo($gameInfo);
                        $usedgb = true;
                        if ($gameId === false) {
                            $gameId = -2;
                            // Leave gamesinfo_id 0 to parse again
                            if ($this->maxHitRequest === true) {
                                $gameId = 0;
                            }
                        }
                    } else {
                        $gameId = $gameCheck['id'];
                    }
                    // Update release.
                    $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', $gameId, $arr['id']));
                } else {
                    // Could not parse release title.
                    $this->pdo->queryExec(sprintf('UPDATE releases SET gamesinfo_id = %d WHERE id = %d', -2, $arr['id']));
                    if ($this->echoOutput) {
                        echo '.';
                    }
                }
                // Sleep to not flood giantbomb.
                $diff = floor((microtime(true) - $startTime) * 1000000);
                if ($this->sleepTime * 1000 - $diff > 0 && $usedgb === true) {
                    usleep($this->sleepTime * 1000 - $diff);
                }
            }
        } else {
            if ($this->echoOutput) {
                $this->pdo->log->doEcho($this->pdo->log->header('No games releases to process.'));
            }
        }
    }
Exemplo n.º 7
0
 public function startRunning()
 {
     if (!$this->isRunning()) {
         return $this->pdo->queryExec("UPDATE tmux SET value = '1' WHERE setting = 'running'");
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * Inserts Genre and returns last affected row (Genre id)
  *
  * @param $genre
  *
  * @return bool
  */
 private function insertGenre($genre)
 {
     $res = '';
     if (isset($genre)) {
         $res = $this->pdo->queryInsert(sprintf("INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)", $this->pdo->escapeString($genre), 6000, 0));
     }
     return $res;
 }
Exemplo n.º 9
0
 /**
  * @param bool $activeOnly
  *
  * @return array
  */
 public function getGenres($activeOnly = false)
 {
     if ($activeOnly) {
         return $this->pdo->query("SELECT musicgenre.* FROM musicgenre INNER JOIN (SELECT DISTINCT musicgenreid FROM musicinfo) x ON x.musicgenreID = musicgenre.id ORDER BY title");
     } else {
         return $this->pdo->query("SELECT * FROM musicgenre ORDER BY title");
     }
 }
Exemplo n.º 10
0
 /**
  * Get a group id for a group name.
  *
  * @param string $groupName
  *
  * @return mixed
  *
  * @access protected
  */
 protected function _getGroupID($groupName)
 {
     if (!isset($this->_groupList[$groupName])) {
         $group = $this->_pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->_pdo->escapeString($groupName)));
         $this->_groupList[$groupName] = $group['id'];
     }
     return $this->_groupList[$groupName];
 }
Exemplo n.º 11
0
 public function data_getForMenuByTypeAndRole($id, $role)
 {
     if ($role == Users::ROLE_ADMIN) {
         $role = "";
     } else {
         $role = sprintf("AND (role = %d OR role = 0)", $role);
     }
     return $this->pdo->query(sprintf("SELECT * FROM content WHERE showinmenu = 1 AND status = 1 AND contenttype = %d %s ", $id, $role));
 }
Exemplo n.º 12
0
 /**
  * Get comments for a user by limit.
  */
 public function getCommentsForUserRange($uid, $start, $num)
 {
     if ($start === false) {
         $limit = "";
     } else {
         $limit = " LIMIT " . $start . "," . $num;
     }
     return $this->pdo->query(sprintf("SELECT release_comments.*, r.guid, r.searchname, users.username FROM release_comments INNER JOIN releases r ON r.id = release_comments.releaseid LEFT OUTER JOIN users ON users.id = release_comments.userid WHERE userid = %d ORDER BY release_comments.createddate DESC " . $limit, $uid));
 }
Exemplo n.º 13
0
    /** This function updates a single variable column in releases
     *  The first parameter is the column to update, the second is the value
     *  The final parameter is the id of the release to update
     *
     * @param string $column
     * @param string|int $status
     * @param int $id
     **/
    private function _updateSingleColumn($column = '', $status = 0, $id = 0)
    {
        if ($column !== '' && $id !== 0) {
            $this->pdo->queryExec(sprintf('
							UPDATE releases
							SET %s = %s
							WHERE id = %d', $column, is_numeric($status) ? $status : $this->pdo->escapeString($status), $id));
        }
    }
Exemplo n.º 14
0
 /**
  * Get forum posts for a user for paged list in profile.
  */
 public function getForUserRange($uid, $start, $num)
 {
     if ($start === false) {
         $limit = "";
     } else {
         $limit = " LIMIT " . $start . "," . $num;
     }
     return $this->pdo->query(sprintf(" SELECT forumpost.*, users.username FROM forumpost LEFT OUTER JOIN users ON users.id = forumpost.userid where userid = %d order by forumpost.createddate desc " . $limit, $uid));
 }
Exemplo n.º 15
0
    /**
     * Retrieves all info for a specific AniDB id
     *
     * @param int $anidbID
     * @return
     */
    public function getAnimeInfo($anidbID)
    {
        $animeInfo = $this->pdo->query(sprintf('SELECT at.anidbid, at.lang, at.title,
				ai.startdate, ai.enddate, ai.updated, ai.related, ai.creators, ai.description,
				ai.rating, ai.picture, ai.categories, ai.characters, ai.type
				FROM anidb_titles AS at LEFT JOIN anidb_info ai USING (anidbid)
				WHERE at.anidbid = %d', $anidbID));
        return isset($animeInfo[0]) ? $animeInfo[0] : false;
    }
Exemplo n.º 16
0
 /**
  * update a release name
  *
  * @param Settings $pdo
  * @param    $id
  * @param    $oldname
  * @param    $newname
  */
 private function updateName(Settings $pdo, $id, $oldname, $newname)
 {
     if ($this->verbose) {
         echo sprintf("OLD : %s\nNEW : %s\n\n", $oldname, $newname);
     }
     if (!$this->echoonly) {
         $this->pdo->queryExec(sprintf("update releases set name=%s, searchname = %s WHERE id = %d", $this->pdo->escapeString($newname), $this->pdo->escapeString($newname), $id));
     }
 }
Exemplo n.º 17
0
 /**
  * Get nzpre data from usenet and parse.
  */
 public function nzpreUpdate()
 {
     if (empty($this->pdo->getSetting('nzpregroup')) || empty($this->pdo->getSetting('nzpresubject')) || empty($this->pdo->getSetting('nzpreposter')) || empty($this->pdo->getSetting('nzprefield')) || empty($this->pdo->getSetting('nzprekey'))) {
         return false;
     }
     if ($this->echooutput) {
         echo "Predb   : Checking for new pre data ";
     }
     $nntp = new NNTP();
     if (!$nntp->doConnect()) {
         echo "Failed to get NNTP connection\n";
         return false;
     }
     $ret = $groupData = $nntp->selectGroup($this->pdo->getSetting('nzpregroup'));
     if ($nntp->isError($ret)) {
         echo "Predb   : Error " . $ret->getMessage() . "\n";
         return false;
     }
     $ret = $groupMsgs = $nntp->getOverview($groupData['last'] - (!empty($this->pdo->getSetting('nzprearticles')) ? $this->pdo->getSetting('nzprearticles') : 500) . '-' . $groupData['last']);
     if ($nntp->isError($ret)) {
         echo "Predb   : Error " . $ret->getMessage() . "\n";
         return false;
     }
     $added_updated = 0;
     $nzprekey = $this->pdo->getSetting('nzprekey');
     while (strlen($nzprekey) < 1024) {
         $nzprekey = $nzprekey . $nzprekey;
     }
     $cnt = !empty($this->pdo->getSetting('nzprearticles')) ? $this->pdo->getSetting('nzprearticles') : 500;
     foreach ($groupMsgs as $groupMsg) {
         if ($cnt % 50 == 0 && $cnt != 0 && $this->echooutput) {
             echo $cnt . "..";
         }
         $cnt--;
         if (preg_match('/^' . $this->pdo->getSetting('nzpresubject') . '$/', $groupMsg['Subject']) && preg_match('/^' . $this->pdo->getSetting('nzpreposter') . '/', $groupMsg['From'])) {
             $ret = $msgHeader = $nntp->getHeader($groupMsg['Message-ID']);
             if ($nntp->isError($ret)) {
                 continue;
             }
             for ($i = 0; $i < count($msgHeader); $i++) {
                 if (preg_match('/^' . $this->pdo->getSetting('nzprefield') . ': /', $msgHeader[$i])) {
                     if ($nzpreParse = $this->nzpreParse(str_replace($this->pdo->getSetting('nzprefield') . ': ', '', $msgHeader[$i]), $nzprekey)) {
                         if ($this->updatePreDB($this->pdo, $nzpreParse)) {
                             $added_updated++;
                         }
                     }
                     break;
                 }
             }
         }
     }
     $nntp->disconnect();
     if ($this->echooutput) {
         echo "\nPredb   : Added/Updated " . $added_updated . " records\n";
     }
 }
Exemplo n.º 18
0
    private function setRageNotFound($Id)
    {
        if ($Id) {
            $this->pdo->queryExec(sprintf('
						UPDATE releases
						SET rageid = -2
						WHERE %s
						AND id = %d', $this->catWhere, $Id));
        }
    }
Exemplo n.º 19
0
    /**
     * Retrieve alternate release with same or similar searchname
     *
     * @param string $guid
     * @param string $searchname
     * @param string $userid
     * @return string
     */
    public function getAlternate($guid, $searchname, $userid)
    {
        //status values
        // 0/false 	= successfully downloaded
        // 1/true 	= failed download
        $this->pdo->queryInsert(sprintf("INSERT IGNORE INTO dnzb_failures (userid, guid) VALUES (%d, %s)", $userid, $this->pdo->escapeString($guid)));
        $alternate = $this->pdo->queryOneRow(sprintf('SELECT * FROM releases r
			WHERE r.searchname %s
			AND r.guid NOT IN (SELECT guid FROM failed_downloads WHERE userid = %d)', $this->pdo->likeString($searchname), $userid));
        return $alternate;
    }
Exemplo n.º 20
0
 /**
  * Process untagged music releases using information from mediainfo if config permits.
  */
 public function processMusicFromMediaInfo()
 {
     $processMediainfo = $this->pdo->getSetting('mediainfopath') != '' ? true : false;
     $processAudioSample = $this->pdo->getSetting('saveaudiopreview') == 1 ? true : false;
     $processMusic = $this->pdo->getSetting('lookupmusic') == 1 ? true : false;
     if ($processMusic && $processMediainfo && $processAudioSample) {
         $music = new Music($this->echooutput);
         $ret = $music->processMusicReleaseFromMediaInfo();
         return $ret;
     }
     return false;
 }
Exemplo n.º 21
0
 /**
  * Get all groups in the DB.
  *
  * @return bool
  * @access protected
  */
 protected function getAllGroups()
 {
     $this->allGroups = [];
     $groups = $this->pdo->query("SELECT id, name FROM groups");
     foreach ($groups as $group) {
         $this->allGroups[$group["name"]] = $group["id"];
     }
     if (count($this->allGroups) === 0) {
         $this->echoOut('You have no groups in your database!');
         return false;
     }
     return true;
 }
Exemplo n.º 22
0
    /**
     * Add new files for a release ID.
     *
     * @param int    $id          The ID of the release.
     * @param string $name        Name of the file.
     * @param int    $size        Size of the file.
     * @param int    $createdTime Unix time the file was created.
     * @param int    $hasPassword Does it have a password (see Releases class constants)?
     *
     * @return mixed
     */
    public function add($id, $name, $size, $createdTime, $hasPassword)
    {
        $insert = 0;
        $duplicateCheck = $this->pdo->queryOneRow(sprintf('
				SELECT id
				FROM releasefiles
				WHERE releaseid = %d AND name = %s', $id, $this->pdo->escapeString(utf8_encode($name))));
        if ($duplicateCheck === false) {
            $insert = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\tINSERT INTO releasefiles\n\t\t\t\t\t\t(releaseid, name, size, createddate, passworded)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(%d, %s, %s, %s, %d)", $id, $this->pdo->escapeString(utf8_encode($name)), $this->pdo->escapeString($size), $this->pdo->from_unixtime($createdTime), $hasPassword));
        }
        return $insert;
    }
Exemplo n.º 23
0
    /**
     * Directs flow for updating child AniDB tables
     *
     * @param array $AniDBInfoArray
     */
    private function updateAniChildTables($AniDBInfoArray = array())
    {
        $check = $this->pdo->queryOneRow(sprintf('
							SELECT ai.anidbid AS info
							FROM anidb_info ai
							WHERE ai.anidbid = %d', $this->anidbId));
        if ($check === false) {
            $picture = $this->insertAniDBInfoEps($AniDBInfoArray);
        } else {
            $picture = $this->updateAniDBInfoEps($AniDBInfoArray);
        }
        if (!empty($picture) && !file_exists($this->imgSavePath . $this->anidbId . ".jpg")) {
            (new \ReleaseImage($this->pdo))->saveImage($this->anidbId, 'http://img7.anidb.net/pics/anime/' . $picture, $this->imgSavePath);
        }
    }
Exemplo n.º 24
0
 /**
  * Insert or update a musicinfo row.
  */
 public function addUpdateMusicInfo($title, $asin, $url, $salesrank, $artist, $publisher, $releasedate, $review, $year, $genreID, $tracks, $cover)
 {
     if (strlen($year) > 4) {
         if (preg_match("/\\d{4}/", $year, $matches)) {
             $year = $this->pdo->escapeString($matches[0]);
         } else {
             $year = "null";
         }
     } else {
         $year = $this->pdo->escapeString($year);
     }
     $sql = sprintf("\n\t\tINSERT INTO musicinfo  (title, asin, url, salesrank,  artist, publisher, releasedate, review, year, genreID, tracks, cover, createddate, updateddate)\n\t\tVALUES (%s, %s, %s,  %s,  %s, %s, %s, %s, %s,   %s, %s, %d, now(), now())\n\t\t\tON DUPLICATE KEY UPDATE  title = %s,  asin = %s,  url = %s,  salesrank = %s,  artist = %s,  publisher = %s,  releasedate = %s,  review = %s,  year = %s,  genreID = %s,  tracks = %s,  cover = %d,  createddate = now(),  updateddate = now()", $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $salesrank, $this->pdo->escapeString($artist), $this->pdo->escapeString($publisher), $releasedate, $this->pdo->escapeString($review), $year, $genreID == -1 ? "null" : $genreID, $this->pdo->escapeString($tracks), $cover, $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $salesrank, $this->pdo->escapeString($artist), $this->pdo->escapeString($publisher), $releasedate, $this->pdo->escapeString($review), $this->pdo->escapeString($year), $genreID == -1 ? "null" : $genreID, $this->pdo->escapeString($tracks), $cover);
     $musicId = $this->pdo->queryInsert($sql);
     return $musicId;
 }
Exemplo n.º 25
0
    /**
     * Safe backfill using posts. Going back to a date specified by the user on the site settings.
     * This does 1 group for x amount of parts until it reaches the date.
     *
     * @param string $articles
     *
     * @return void
     */
    public function safeBackfill($articles = '')
    {
        $groupname = $this->pdo->queryOneRow(sprintf('
				SELECT name FROM groups
				WHERE first_record_postdate BETWEEN %s AND NOW()
				AND backfill = 1
				ORDER BY name ASC', $this->pdo->escapeString($this->_safeBackFillDate)));
        if (!$groupname) {
            $dMessage = 'No groups to backfill, they are all at the target date ' . $this->_safeBackFillDate . ", or you have not enabled them to be backfilled in the groups page.\n";
            if ($this->_debug) {
                $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL);
            }
            exit($dMessage);
        } else {
            $this->backfillAllGroups($groupname['name'], $articles);
        }
    }
Exemplo n.º 26
0
 /**
  * Attempts to get the releasename from a par2 file
  *
  * @param string $guid
  * @param int    $relID
  * @param int    $groupID
  * @param int    $nameStatus
  * @param int    $show
  *
  * @return bool
  *
  * @access public
  */
 public function checkPAR2($guid, $relID, $groupID, $nameStatus, $show)
 {
     $nzbFile = $this->LoadNZB($guid);
     if ($nzbFile !== false) {
         foreach ($nzbFile->file as $nzbContents) {
             if (preg_match('/\\.(par[2" ]|\\d{2,3}").+\\(1\\/1\\)$/i', (string) $nzbContents->attributes()->subject)) {
                 if ($this->pp->parsePAR2((string) $nzbContents->segments->segment, $relID, $groupID, $this->nntp, $show) === true && $nameStatus === 1) {
                     $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID));
                     return true;
                 }
             }
         }
     }
     if ($nameStatus === 1) {
         $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID));
     }
     return false;
 }
Exemplo n.º 27
0
    /**
     * Write an NZB to the hard drive for a single release.
     *
     * @param int    $relID   The id of the release in the DB.
     * @param string $relGuid The guid of the release.
     * @param string $name    The name of the release.
     * @param string $cTitle  The name of the category this release is in.
     *
     * @return bool Have we successfully written the NZB to the hard drive?
     *
     * @access public
     */
    public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle)
    {
        $path = $this->buildNZBPath($relGuid, $this->nzbSplitLevel, true) . $relGuid . '.nzb.gz';
        $fp = gzopen($path, 'wb7');
        if ($fp) {
            $nzb_guid = '';
            gzwrite($fp, sprintf($this->_nzbHeadString, htmlspecialchars($cTitle, ENT_QUOTES, 'utf-8'), htmlspecialchars($name, ENT_QUOTES, 'utf-8')));
            $binaries = $this->pdo->queryDirect($this->_binariesQuery . $relID . ' ORDER BY name');
            if ($binaries instanceof \Traversable) {
                foreach ($binaries as $binary) {
                    $poster = htmlspecialchars($binary['fromname'], ENT_QUOTES, 'utf-8');
                    if ($binary instanceof \Traversable) {
                        foreach ($binary as $bin) {
                            // Buffer segment writes, increases performance.
                            $string = '';
                            $parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $bin['id']));
                            if ($parts instanceof \Traversable) {
                                foreach ($parts as $part) {
                                    if ($nzb_guid === '') {
                                        $nzb_guid = $part['messageid'];
                                    }
                                    $string .= '  <segment bytes="' . $part['size'] . '" number="' . $part['partnumber'] . '">' . htmlspecialchars($part['messageid'], ENT_QUOTES, 'utf-8') . "</segment>\n";
                                }
                            }
                            gzwrite($fp, '<file poster="' . $poster . '" date="' . $bin['udate'] . '" subject="' . htmlspecialchars($bin['name'], ENT_QUOTES, 'utf-8') . ' (1/' . $bin['totalparts'] . ")\">\n <groups>\n  <group>" . $bin['groupname'] . "</group>\n </groups>\n <segments>\n" . $string . " </segments>\n</file>\n");
                        }
                    }
                }
            }
            gzwrite($fp, '</nzb>');
            gzclose($fp);
            if (is_file($path)) {
                $this->pdo->queryExec(sprintf('
						UPDATE releases SET nzbstatus = %d %s WHERE id = %d', NZB::NZB_ADDED, $nzb_guid === '' ? '' : ', nzb_guid = UNHEX( ' . $this->pdo->escapestring(md5($nzb_guid)) . ' )', $relID));
                // Chmod to fix issues some users have with file permissions.
                chmod($path, 0777);
                return true;
            } else {
                echo "ERROR: {$path} does not exist.\n";
            }
        }
        return false;
    }
Exemplo n.º 28
0
    /**
     * Try to get a title from a Linux_2rename.sh file for alt.binaries.u4e group.
     *
     * @param $fileLocation
     */
    protected function _processU4ETitle($fileLocation)
    {
        // Open the file for reading.
        $handle = @fopen($fileLocation, 'r');
        // Check if it failed.
        if ($handle) {
            // Loop over the file line by line.
            while (($buffer = fgets($handle, 16384)) !== false) {
                // Check if we find the word
                if (stripos($buffer, 'mkdir') !== false) {
                    // Get a new name.
                    $newName = trim(str_replace('mkdir ', '', $buffer));
                    // Check if it's a empty string or not.
                    if (empty($newName)) {
                        continue;
                    }
                    // Get a new category id.
                    $newCategory = $this->_categorize->determineCategory($this->_release['groupid'], $newName);
                    $newTitle = $this->pdo->escapeString(substr($newName, 0, 255));
                    // Update the release with the data.
                    $this->pdo->queryExec(sprintf('
							UPDATE releases
							SET rageid = -1, seriesfull = NULL, season = NULL, episode = NULL,
								tvtitle = NULL, tvairdate = NULL, imdbid = NULL, musicinfoid = NULL,
								consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, prehashid = 0,
								searchname = %s, isrenamed = 1, iscategorized = 1, proc_files = 1, categoryid = %d
							WHERE id = %d', $newTitle, $newCategory, $this->_release['id']));
                    $this->sphinx->updateRelease($this->_release['id'], $this->pdo);
                    // Echo the changed name to CLI.
                    if ($this->_echoCLI) {
                        \NameFixer::echoChangedReleaseName(['new_name' => $newName, 'old_name' => $this->_release['searchname'], 'new_category' => $newCategory, 'old_category' => $this->_release['categoryid'], 'group' => $this->_release['groupid'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_processU4ETitle']);
                    }
                    // Break out of the loop.
                    break;
                }
            }
            // Close the file.
            fclose($handle);
        }
        // Delete the file.
        @unlink($fileLocation);
    }
Exemplo n.º 29
0
 /**
  * Insert or update a bookinfo row.
  */
 public function addUpdateBookInfo($title, $asin, $url, $author, $publisher, $publishdate, $review, $cover, $dewey, $ean, $isbn, $pages)
 {
     if ($pages == 0) {
         $pages = "null";
     } else {
         $pages = $pages + 0;
     }
     if ($publishdate == "") {
         $publishdate = "null";
     } elseif (strlen($publishdate) == 4) {
         $publishdate = $this->pdo->escapeString($publishdate . "-01-01");
     } elseif (strlen($publishdate) == 7) {
         $publishdate = $this->pdo->escapeString($publishdate . "-01");
     } else {
         $publishdate = $this->pdo->escapeString($publishdate);
     }
     $sql = sprintf("INSERT INTO bookinfo  (title, asin, url, author, publisher, publishdate, review, cover, createddate, updateddate, dewey, ean, isbn, pages)\n\t\tVALUES (%s,  %s, %s, %s, %s, %s,  %s, %d, now(), now(), %s, %s, %s, %s)\n\t\t\tON DUPLICATE KEY UPDATE  title = %s,  asin = %s,  url = %s,   author = %s,  publisher = %s,  publishdate = %s,  review = %s, cover = %d,  createddate = now(),  updateddate = now(), dewey = %s, ean = %s, isbn = %s, pages = %s", $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $publishdate, $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages, $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $this->pdo->escapeString($publishdate), $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages);
     $bookId = $this->pdo->queryInsert($sql);
     return $bookId;
 }
Exemplo n.º 30
0
 /**
  * Get an episodeinfo row by name.
  */
 public function getEpisodeInfoByName($showtitle, $fullep, $epabsolute = '0')
 {
     $db = new Settings();
     if ($epabsolute == '0') {
         //as string - not int.
         if (!preg_match('/[21]\\d{3}\\/\\d{2}\\/\\d{2}/', $fullep)) {
             $additionalSql = sprintf('AND fullep = %s', $db->escapeString($fullep));
         } else {
             $additionalSql = sprintf('AND airdate LIKE %s', $db->escapeString($fullep . ' %'));
         }
     } else {
         $additionalSql = sprintf('AND epabsolute = %s', $db->escapeString($epabsolute));
     }
     return $db->queryOneRow(sprintf('SELECT * FROM episodeinfo WHERE showtitle = %s %s', $db->escapeString($showtitle), $additionalSql));
 }