mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-02 03:08:53 +00:00
Update classes, add constructors, simplify functions.
This commit is contained in:
@@ -8,13 +8,26 @@ use newznab\db\Settings;
|
||||
*/
|
||||
class ReleaseComments
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \newznab\db\Settings
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @param \newznab\db\Settings $settings
|
||||
*/
|
||||
public function __construct($settings = null)
|
||||
{
|
||||
$this->pdo = ($settings instanceof Settings ? $settings : new Settings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a comment by id.
|
||||
*/
|
||||
public function getCommentById($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
return $db->queryOneRow(sprintf("SELECT * FROM releasecomment WHERE id = %d", $id));
|
||||
return $this->pdo->queryOneRow(sprintf("SELECT * FROM releasecomment WHERE id = %d", $id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,8 +35,7 @@ class ReleaseComments
|
||||
*/
|
||||
public function getCommentsByGid($gid)
|
||||
{
|
||||
$db = new Settings();
|
||||
return $db->query(sprintf("SELECT rc.id, text, createddate, sourceid, CASE WHEN sourceid = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username, CASE WHEN sourceid = 0 THEN (SELECT role FROM users WHERE id = userid) ELSE '-1' END AS role, CASE WHEN sourceid =0 THEN (SELECT r.name AS rolename FROM users AS u LEFT JOIN userroles AS r ON r.id = u.role WHERE u.id = userid) ELSE (SELECT description AS rolename FROM spotnabsources WHERE id = sourceid) END AS rolename FROM releasecomment rc WHERE isvisible = 1 AND gid = %s AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC LIMIT 100", $db->escapeString($gid)));
|
||||
return $this->pdo->query(sprintf("SELECT rc.id, text, createddate, sourceid, CASE WHEN sourceid = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username, CASE WHEN sourceid = 0 THEN (SELECT role FROM users WHERE id = userid) ELSE '-1' END AS role, CASE WHEN sourceid =0 THEN (SELECT r.name AS rolename FROM users AS u LEFT JOIN userroles AS r ON r.id = u.role WHERE u.id = userid) ELSE (SELECT description AS rolename FROM spotnabsources WHERE id = sourceid) END AS rolename FROM releasecomment rc WHERE isvisible = 1 AND gid = %s AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC LIMIT 100", $this->pdo->escapeString($gid)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,8 +43,7 @@ class ReleaseComments
|
||||
*/
|
||||
public function getCommentsByGuid($guid)
|
||||
{
|
||||
$db = new Settings();
|
||||
return $db->query(sprintf("SELECT rc.id, text, createddate, sourceid, CASE WHEN sourceid = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username FROM releasecomment rc LEFT JOIN releases r ON r.gid = rc.gid WHERE isvisible = 1 AND guid = %s AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC LIMIT 100", $db->escapeString($guid)));
|
||||
return $this->pdo->query(sprintf("SELECT rc.id, text, createddate, sourceid, CASE WHEN sourceid = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username FROM releasecomment rc LEFT JOIN releases r ON r.gid = rc.gid WHERE isvisible = 1 AND guid = %s AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC LIMIT 100", $this->pdo->escapeString($guid)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +51,6 @@ class ReleaseComments
|
||||
*/
|
||||
public function getCommentCount($refdate=Null, $localOnly=Null)
|
||||
{
|
||||
$db = new Settings();
|
||||
if($refdate !== Null){
|
||||
if(is_string($refdate)){
|
||||
// ensure we're in the right format
|
||||
@@ -55,7 +65,7 @@ class ReleaseComments
|
||||
}
|
||||
|
||||
$q = "SELECT count(id) AS num FROM releasecomment";
|
||||
$clause = array();
|
||||
$clause = [];
|
||||
if($refdate !== Null)
|
||||
$clause[] = "createddate >= '$refdate'";
|
||||
|
||||
@@ -63,15 +73,15 @@ class ReleaseComments
|
||||
// set localOnly to true to only receive local comment count
|
||||
// set localOnly to false to only receive remote comment count
|
||||
if($localOnly === true){
|
||||
$clause[] = "sourceID = 0";
|
||||
$clause[] = "sourceid = 0";
|
||||
}else if($localOnly === false){
|
||||
$clause[] = "sourceID != 0";
|
||||
$clause[] = "sourceid != 0";
|
||||
}
|
||||
|
||||
if(count($clause))
|
||||
$q .= " WHERE ".implode(" AND ", $clause);
|
||||
|
||||
$res = $db->queryOneRow($q);
|
||||
$res = $this->pdo->queryOneRow($q);
|
||||
return $res["num"];
|
||||
}
|
||||
|
||||
@@ -80,11 +90,10 @@ class ReleaseComments
|
||||
*/
|
||||
public function deleteComment($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
$res = $this->getCommentById($id);
|
||||
if ($res)
|
||||
{
|
||||
$db->queryExec(sprintf("update releasecomment SET isvisible = 0 WHERE id = %d", $id));
|
||||
$this->pdo->queryExec(sprintf("update releasecomment SET isvisible = 0 WHERE id = %d", $id));
|
||||
$this->updateReleaseCommentCount($res["gid"]);
|
||||
}
|
||||
}
|
||||
@@ -94,11 +103,10 @@ class ReleaseComments
|
||||
*/
|
||||
public function deleteCommentsForRelease($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
$res = $this->getCommentById($id);
|
||||
if ($res)
|
||||
{
|
||||
$db->queryExec(sprintf("DELETE rc.* FROM releasecomment rc JOIN releases r ON r.gid = rc.gid WHERE r.id = %d", $id));
|
||||
$this->pdo->queryExec(sprintf("DELETE rc.* FROM releasecomment rc JOIN releases r ON r.gid = rc.gid WHERE r.id = %d", $id));
|
||||
$this->updateReleaseCommentCount($res["gid"]);
|
||||
}
|
||||
}
|
||||
@@ -108,8 +116,6 @@ class ReleaseComments
|
||||
*/
|
||||
public function deleteCommentsForUser($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
$numcomments = $this->getCommentCountForUser($id);
|
||||
if ($numcomments > 0)
|
||||
{
|
||||
@@ -130,11 +136,10 @@ class ReleaseComments
|
||||
if(strlen(trim($text)) == 0)
|
||||
return false;
|
||||
|
||||
$db = new Settings();
|
||||
if ($db->getSetting('storeuserips') != "1")
|
||||
if ($this->pdo->getSetting('storeuserips') != "1")
|
||||
$host = "";
|
||||
|
||||
$comid = $db->queryInsert(sprintf("INSERT INTO releasecomment (releaseid, gid, text, userid, createddate, host) VALUES (%d, %s, %s, %d, now(), %s)", $id, $db->escapeString($gid), $db->escapeString($text), $userid, $db->escapeString($host)));
|
||||
$comid = $this->pdo->queryInsert(sprintf("INSERT INTO releasecomment (releaseid, gid, text, userid, createddate, host) VALUES (%d, %s, %s, %d, now(), %s)", $id, $this->pdo->escapeString($gid), $this->pdo->escapeString($text), $userid, $this->pdo->escapeString($host)));
|
||||
$this->updateReleaseCommentCount($gid);
|
||||
return $comid;
|
||||
}
|
||||
@@ -144,15 +149,13 @@ class ReleaseComments
|
||||
*/
|
||||
public function getCommentsRange($start, $num)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
if ($start === false)
|
||||
$limit = "";
|
||||
else
|
||||
$limit = " LIMIT ".$start.",".$num;
|
||||
|
||||
$sql = "SELECT rc.id, userid, guid, text, createddate, sourceid, CASE WHEN sourceID = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username, CASE WHEN sourceid = 0 THEN (SELECT role FROM users WHERE id = userid) ELSE '-1' END AS role, CASE WHEN sourceid =0 THEN (SELECT r.name AS rolename FROM users AS u LEFT JOIN userroles AS r ON r.id = u.role WHERE u.id = userid) ELSE (SELECT description AS rolename FROM spotnabsources WHERE id = sourceid) END AS rolename FROM releasecomment rc LEFT JOIN releases r ON r.gid = rc.gid WHERE isvisible = 1 AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC ".$limit;
|
||||
return $db->query($sql);
|
||||
return $this->pdo->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,10 +163,9 @@ class ReleaseComments
|
||||
*/
|
||||
public function updateReleaseCommentCount($gid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("update releases
|
||||
$this->pdo->queryExec(sprintf("update releases
|
||||
SET comments = (SELECT count(id) FROM releasecomment WHERE releasecomment.gid = releases.gid AND isvisible = 1)
|
||||
WHERE releases.gid = %s", $db->escapeString($gid) ));
|
||||
WHERE releases.gid = %s", $this->pdo->escapeString($gid) ));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +173,7 @@ class ReleaseComments
|
||||
*/
|
||||
public function getCommentCountForUser($uid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$res = $db->queryOneRow(sprintf("SELECT count(id) AS num FROM releasecomment WHERE userid = %d AND isvisible = 1", $uid));
|
||||
$res = $this->pdo->queryOneRow(sprintf("SELECT count(id) AS num FROM releasecomment WHERE userid = %d AND isvisible = 1", $uid));
|
||||
return $res["num"];
|
||||
}
|
||||
|
||||
@@ -181,13 +182,11 @@ class ReleaseComments
|
||||
*/
|
||||
public function getCommentsForUserRange($uid, $start, $num)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
if ($start === false)
|
||||
$limit = "";
|
||||
else
|
||||
$limit = " LIMIT ".$start.",".$num;
|
||||
|
||||
return $db->query(sprintf("SELECT releasecomment.*, r.guid, r.searchname, users.username FROM releasecomment INNER JOIN releases r ON r.id = releasecomment.releaseid LEFT OUTER JOIN users ON users.id = releasecomment.userid WHERE userid = %d ORDER BY releasecomment.createddate DESC ".$limit, $uid));
|
||||
return $this->pdo->query(sprintf("SELECT releasecomment.*, r.guid, r.searchname, users.username FROM releasecomment INNER JOIN releases r ON r.id = releasecomment.releaseid LEFT OUTER JOIN users ON users.id = releasecomment.userid WHERE userid = %d ORDER BY releasecomment.createddate DESC ".$limit, $uid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,52 +13,64 @@ class ReleaseExtra
|
||||
const VIDEO_RESOLUTION_720 = 2;
|
||||
const VIDEO_RESOLUTION_1080 = 3;
|
||||
|
||||
/**
|
||||
* @var \newznab\db\Settings
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @param \newznab\db\Settings $settings
|
||||
*/
|
||||
public function __construct($settings = null)
|
||||
{
|
||||
$this->pdo = ($settings instanceof Settings ? $settings : new Settings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a codec string to a user friendly format.
|
||||
*/
|
||||
public function makeCodecPretty($codec)
|
||||
{
|
||||
if (preg_match("/DX50|DIVX|DIV3/i", $codec))
|
||||
return "DivX";
|
||||
if (preg_match("/XVID/i", $codec))
|
||||
return "XviD";
|
||||
if (preg_match("/^27$/i", $codec))
|
||||
return "Blu-Ray";
|
||||
if (preg_match("/V_MPEG4\/ISO\/AVC/i", $codec))
|
||||
return "x264";
|
||||
if (preg_match("/wmv|WVC1/i", $codec))
|
||||
return "wmv";
|
||||
if (preg_match("/^2$/i", $codec))
|
||||
return "HD.ts";
|
||||
if (preg_match("/avc1/i", $codec))
|
||||
return "h.264";
|
||||
if (preg_match("/DX50|DIVX|DIV3/i", $codec))
|
||||
return "DivX";
|
||||
|
||||
if (preg_match('/DX50|DIVX|DIV3/i', $codec)) {
|
||||
return 'DivX';
|
||||
}
|
||||
if (preg_match('/XVID/i', $codec)) {
|
||||
return 'XviD';
|
||||
}
|
||||
if (preg_match('/^27$/i', $codec)) {
|
||||
return 'Blu-Ray';
|
||||
}
|
||||
if (preg_match('/V_MPEG4\/ISO\/AVC/i', $codec)) {
|
||||
return 'x264';
|
||||
}
|
||||
if (preg_match('/wmv|WVC1/i', $codec)) {
|
||||
return 'wmv';
|
||||
}
|
||||
if (preg_match('/^2$/i', $codec)) {
|
||||
return 'HD.ts';
|
||||
}
|
||||
if (preg_match('/avc1/i', $codec)) {
|
||||
return 'h.264';
|
||||
}
|
||||
return $codec;
|
||||
}
|
||||
|
||||
public function getAudio($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->query(sprintf("select * from releaseaudio where releaseid = %d order by audioID ASC", $id));
|
||||
return $this->pdo->query(sprintf("select * from releaseaudio where releaseid = %d order by audioid ASC", $id));
|
||||
}
|
||||
|
||||
public function getBriefByGuid($guid)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->queryOneRow(sprintf("select containerformat,videocodec,videoduration,videoaspect, concat(releasevideo.videowidth,'x',releasevideo.videoheight,' @',format(videoframerate,0),'fps') as size, group_concat(distinct releaseaudio.audiolanguage SEPARATOR ', ') as audio, group_concat(distinct releaseaudio.audiobitrate SEPARATOR ', ') as audiobitrate, group_concat(distinct releaseaudio.audioformat SEPARATOR ', ') as audioformat, group_concat(distinct releaseaudio.audiomode SEPARATOR ', ') as audiomode, group_concat(distinct releaseaudio.audiobitratemode SEPARATOR ', ') as audiobitratemode, group_concat(distinct releasesubs.subslanguage SEPARATOR ', ') as subs from releaseaudio left outer join releasesubs on releaseaudio.releaseid = releasesubs.releaseid left outer join releasevideo on releasevideo.releaseid = releaseaudio.releaseid inner join releases r on r.id = releaseaudio.releaseid where r.guid = %s group by r.id", $db->escapeString($guid)));
|
||||
return $this->pdo->queryOneRow(sprintf("select containerformat,videocodec,videoduration,videoaspect, concat(releasevideo.videowidth,'x',releasevideo.videoheight,' @',format(videoframerate,0),'fps') as size, group_concat(distinct releaseaudio.audiolanguage SEPARATOR ', ') as audio, group_concat(distinct releaseaudio.audiobitrate SEPARATOR ', ') as audiobitrate, group_concat(distinct releaseaudio.audioformat SEPARATOR ', ') as audioformat, group_concat(distinct releaseaudio.audiomode SEPARATOR ', ') as audiomode, group_concat(distinct releaseaudio.audiobitratemode SEPARATOR ', ') as audiobitratemode, group_concat(distinct releasesubs.subslanguage SEPARATOR ', ') as subs from releaseaudio left outer join releasesubs on releaseaudio.releaseid = releasesubs.releaseid left outer join releasevideo on releasevideo.releaseid = releaseaudio.releaseid inner join releases r on r.id = releaseaudio.releaseid where r.guid = %s group by r.id", $this->pdo->escapeString($guid)));
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("DELETE from releaseaudio where releaseid = %d", $id));
|
||||
$db->queryExec(sprintf("DELETE from releasesubs where releaseid = %d", $id));
|
||||
$db->queryExec(sprintf("DELETE from releaseextrafull where releaseid = %d", $id));
|
||||
$db->queryExec(sprintf("DELETE from releasevideo where releaseid = %d", $id));
|
||||
$this->pdo->queryExec(sprintf("DELETE from releaseaudio where releaseid = %d", $id));
|
||||
$this->pdo->queryExec(sprintf("DELETE from releasesubs where releaseid = %d", $id));
|
||||
$this->pdo->queryExec(sprintf("DELETE from releaseextrafull where releaseid = %d", $id));
|
||||
$this->pdo->queryExec(sprintf("DELETE from releasevideo where releaseid = %d", $id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,8 +177,6 @@ class ReleaseExtra
|
||||
*/
|
||||
public function addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
$row = $this->getVideo($releaseID);
|
||||
if ($row)
|
||||
return -1;
|
||||
@@ -176,24 +186,20 @@ class ReleaseExtra
|
||||
else
|
||||
$videoframerate = 0.0;
|
||||
|
||||
$sql = sprintf("insert into releasevideo
|
||||
return $this->pdo->queryInsert(sprintf('INSERT INTO releasevideo
|
||||
(releaseid, containerformat, overallbitrate, videoduration,
|
||||
videoformat, videocodec, videowidth, videoheight,
|
||||
videoaspect, videoframerate, videolibrary, definition)
|
||||
values ( %d, %s, %s, %s, %s, %s, %d, %d, %s, %s, %s, %d )",
|
||||
$releaseID, $db->escapeString($containerformat), $db->escapeString($overallbitrate), $db->escapeString($videoduration),
|
||||
$db->escapeString($videoformat), $db->escapeString($videocodec), $videowidth, $videoheight,
|
||||
$db->escapeString($videoaspect), $db->escapeString($videoframerate), $db->escapeString($videolibrary), self::determineVideoResolution($videowidth, $videoheight)
|
||||
);
|
||||
|
||||
return $db->queryInsert($sql);
|
||||
videoaspect, videoframerate, videolibrary, definition)
|
||||
VALUES ( %d, %s, %s, %s, %s, %s, %d, %d, %s, %s, %s, %d )',
|
||||
$releaseID, $this->pdo->escapeString($containerformat), $this->pdo->escapeString($overallbitrate), $this->pdo->escapeString($videoduration),
|
||||
$this->pdo->escapeString($videoformat), $this->pdo->escapeString($videocodec), $videowidth, $videoheight,
|
||||
$this->pdo->escapeString($videoaspect), $this->pdo->escapeString($videoframerate), $this->pdo->escapeString($videolibrary), self::determineVideoResolution($videowidth, $videoheight)
|
||||
));
|
||||
}
|
||||
|
||||
public function getVideo($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->queryOneRow(sprintf("select * from releasevideo where releaseid = %d", $id));
|
||||
return $this->pdo->queryOneRow(sprintf("select * from releasevideo where releaseid = %d", $id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,8 +236,6 @@ class ReleaseExtra
|
||||
return self::VIDEO_RESOLUTION_1080; //HD 1080
|
||||
}
|
||||
|
||||
return self::VIDEO_RESOLUTION_NA; //catch all
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,71 +243,57 @@ class ReleaseExtra
|
||||
*/
|
||||
public function addAudio($releaseID, $audioID, $audioformat, $audiomode, $audiobitratemode, $audiobitrate, $audiochannels, $audiosamplerate, $audiolibrary, $audiolanguage, $audiotitle)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
$row = $this->getAudioAndChannel($releaseID, $audioID);
|
||||
if ($row)
|
||||
return -1;
|
||||
|
||||
$sql = sprintf("insert into releaseaudio
|
||||
(releaseid, audioID,audioformat,audiomode, audiobitratemode, audiobitrate,
|
||||
return $this->pdo->queryInsert(sprintf("INSERT INTO releaseaudio
|
||||
(releaseid, audioid,audioformat,audiomode, audiobitratemode, audiobitrate,
|
||||
audiochannels,audiosamplerate,audiolibrary,audiolanguage,audiotitle)
|
||||
values ( %d, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s )",
|
||||
$releaseID, $audioID, $db->escapeString($audioformat), $db->escapeString($audiomode), $db->escapeString($audiobitratemode),
|
||||
$db->escapeString($audiobitrate), $db->escapeString($audiochannels), $db->escapeString($audiosamplerate), $db->escapeString(substr($audiolibrary, 0, 255)),
|
||||
$db->escapeString(substr($audiolanguage, 0, 255)), $db->escapeString(substr($audiotitle, 0, 255))
|
||||
);
|
||||
|
||||
return $db->queryInsert($sql);
|
||||
VALUES ( %d, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s )",
|
||||
$releaseID, $audioID, $this->pdo->escapeString($audioformat), $this->pdo->escapeString($audiomode), $this->pdo->escapeString($audiobitratemode),
|
||||
$this->pdo->escapeString($audiobitrate), $this->pdo->escapeString($audiochannels), $this->pdo->escapeString($audiosamplerate), $this->pdo->escapeString(substr($audiolibrary, 0, 255)),
|
||||
$this->pdo->escapeString(substr($audiolanguage, 0, 255)), $this->pdo->escapeString(substr($audiotitle, 0, 255))
|
||||
));
|
||||
}
|
||||
|
||||
public function getAudioAndChannel($rid, $aid)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->queryOneRow(sprintf("select * from releaseaudio where releaseid = %d and audioID = %d", $rid, $aid));
|
||||
return $this->pdo->queryOneRow(sprintf("select * from releaseaudio where releaseid = %d and audioid = %d", $rid, $aid));
|
||||
}
|
||||
|
||||
public function addSubs($releaseID, $subsID, $subslanguage)
|
||||
{
|
||||
$db = new Settings();
|
||||
$row = $this->getSubs($releaseID);
|
||||
if ($row)
|
||||
return -1;
|
||||
|
||||
$sql = sprintf("insert into releasesubs (releaseid, subsID, subslanguage) values ( %d, %d, %s)", $releaseID, $subsID, $db->escapeString($subslanguage));
|
||||
$sql = sprintf("INSERT INTO releasesubs (releaseid, subsid, subslanguage) VALUES ( %d, %d, %s)", $releaseID, $subsID, $this->pdo->escapeString($subslanguage));
|
||||
|
||||
return $db->queryInsert($sql);
|
||||
return $this->pdo->queryInsert($sql);
|
||||
}
|
||||
|
||||
public function getSubs($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->queryOneRow(sprintf("SELECT group_concat(subslanguage SEPARATOR ', ') as subs FROM `releasesubs` WHERE `releaseid` = %d ORDER BY `subsID` ASC", $id));
|
||||
return $this->pdo->queryOneRow(sprintf("SELECT group_concat(subslanguage SEPARATOR ', ') as subs FROM releasesubs WHERE releaseid = %d ORDER BY subsid ASC", $id));
|
||||
}
|
||||
|
||||
public function deleteFull($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->queryExec(sprintf("DELETE from releaseextrafull where releaseid = %d", $id));
|
||||
return $this->pdo->queryExec(sprintf("DELETE from releaseextrafull where releaseid = %d", $id));
|
||||
}
|
||||
|
||||
public function addFull($id, $xml)
|
||||
{
|
||||
$db = new Settings();
|
||||
$row = $this->getFull($id);
|
||||
if ($row)
|
||||
return -1;
|
||||
|
||||
return $db->queryInsert(sprintf("insert into releaseextrafull (releaseid, mediainfo) values (%d, %s)", $id, $db->escapeString($xml)));
|
||||
return $this->pdo->queryInsert(sprintf("INSERT INTO releaseextrafull (releaseid, mediainfo) VALUES (%d, %s)", $id, $this->pdo->escapeString($xml)));
|
||||
}
|
||||
|
||||
public function getFull($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
return $db->queryOneRow(sprintf("select * from releaseextrafull where releaseid = %d", $id));
|
||||
return $this->pdo->queryOneRow(sprintf("select * from releaseextrafull where releaseid = %d", $id));
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,26 @@ use newznab\db\Settings;
|
||||
*/
|
||||
class ReleaseFiles
|
||||
{
|
||||
/**
|
||||
* @var \newznab\db\Settings
|
||||
*/
|
||||
protected $pdo;
|
||||
|
||||
/**
|
||||
* @param \newznab\db\Settings $settings
|
||||
*/
|
||||
public function __construct($settings = null)
|
||||
{
|
||||
$this->pdo = ($settings instanceof Settings ? $settings : new Settings());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get releasefiles row by id.
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
return $db->query(sprintf("select * from releasefiles where releaseid = %d order by releasefiles.name ", $id));
|
||||
return $this->pdo->query(sprintf("SELECT * FROM releasefiles WHERE releaseid = %d ORDER BY releasefiles.name ", $id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,8 +34,7 @@ class ReleaseFiles
|
||||
*/
|
||||
public function getByGuid($guid)
|
||||
{
|
||||
$db = new Settings();
|
||||
return $db->query(sprintf("select releasefiles.* from releasefiles inner join releases r on r.id = releasefiles.releaseid where r.guid = %s order by releasefiles.name ", $db->escapeString($guid)));
|
||||
return $this->pdo->query(sprintf("SELECT releasefiles.* FROM releasefiles INNER JOIN releases r ON r.id = releasefiles.releaseid WHERE r.guid = %s ORDER BY releasefiles.name ", $this->pdo->escapeString($guid)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,8 +42,7 @@ class ReleaseFiles
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$db = new Settings();
|
||||
return $db->queryExec(sprintf("DELETE from releasefiles where releaseid = %d", $id));
|
||||
return $this->pdo->queryExec(sprintf("DELETE FROM releasefiles WHERE releaseid = %d", $id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,8 +50,11 @@ class ReleaseFiles
|
||||
*/
|
||||
public function add($id, $name, $size, $createddate, $passworded)
|
||||
{
|
||||
$db = new Settings();
|
||||
$sql = sprintf("INSERT INTO releasefiles (releaseid, name, size, createddate, passworded) VALUES (%d, %s, %s, from_unixtime(%d), %d)", $id, $db->escapeString($name), $db->escapeString($size), $createddate, $passworded );
|
||||
return $db->queryInsert($sql);
|
||||
return $this->pdo->queryInsert(sprintf("INSERT INTO releasefiles (releaseid, name, size, createddate, passworded) VALUES
|
||||
(%d, %s, %s, from_unixtime(%d), %d)",
|
||||
$id, $this->pdo->escapeString($name), $this->pdo->escapeString($size),
|
||||
$createddate, $passworded
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,6 @@ class ReleaseRegex
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @var \newznab\controllers\Sites
|
||||
*/
|
||||
public $site;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->regexes = [];
|
||||
@@ -226,7 +221,7 @@ class ReleaseRegex
|
||||
|
||||
if (isset($matches['name']) && isset($matches['parts'])) {
|
||||
if (strpos($matches['parts'], '/') === false) {
|
||||
$matches['parts'] = str_replace(array('-', '~', ' of '), '/', $matches['parts']);
|
||||
$matches['parts'] = str_replace(['-', '~', ' of '], '/', $matches['parts']);
|
||||
}
|
||||
|
||||
$regcatid = "null ";
|
||||
@@ -294,7 +289,7 @@ class ReleaseRegex
|
||||
if ($ignorematched !== '' && ($rowbin['regexid'] != '' || $rowbin['blacklistid'] == 1))
|
||||
continue;
|
||||
|
||||
$regexarr = array("id" => "", 'regex' => $regex, 'poster' => $poster, "categoryid" => "");
|
||||
$regexarr = ["id" => "", 'regex' => $regex, 'poster' => $poster, "categoryid" => ""];
|
||||
$regexCheck = $this->performMatch($regexarr, $rowbin['name'], $rowbin['fromname']);
|
||||
|
||||
if ($regexCheck !== false) {
|
||||
@@ -345,14 +340,14 @@ class ReleaseRegex
|
||||
|
||||
$groupsToFetch = [];
|
||||
if (preg_match('/^[a-z]{2,3}(\.[a-z0-9\-]+)+$/', $groupname))
|
||||
$groupsToFetch[] = array('name' => $groupname);
|
||||
$groupsToFetch[] = ['name' => $groupname];
|
||||
elseif ($groupname === 0)
|
||||
$groupsToFetch = $groups->getAll();
|
||||
else {
|
||||
$newsgroups = $nntp->getGroups();
|
||||
foreach ($newsgroups as $ngroup) {
|
||||
if (preg_match('/' . $groupname . '/', $ngroup['group']))
|
||||
$groupsToFetch[] = array('name' => $ngroup['group']);
|
||||
$groupsToFetch[] = ['name' => $ngroup['group']];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +423,7 @@ class ReleaseRegex
|
||||
$binSetData = [];
|
||||
|
||||
foreach ($headers as $subject => $data) {
|
||||
$binData = array(
|
||||
$binData = [
|
||||
'name' => $subject,
|
||||
'fromname' => $data['From'],
|
||||
'date' => $data['Date'],
|
||||
@@ -442,7 +437,7 @@ class ReleaseRegex
|
||||
'relname' => "null",
|
||||
'relpart' => "null",
|
||||
'reltotalpart' => "null"
|
||||
);
|
||||
];
|
||||
|
||||
//Filter binaries based on black/white list
|
||||
if ($binaries->isBlackListed($data, $group)) {
|
||||
|
||||
@@ -2,51 +2,61 @@
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
/**
|
||||
* Class UserMovies
|
||||
*/
|
||||
class UserMovies
|
||||
{
|
||||
public function addMovie($uid, $imdbid, $catid=array())
|
||||
/**
|
||||
* @var \newznab\db\Settings
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @param array $options Class instances.
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$db = new Settings();
|
||||
$defaults = [
|
||||
'Settings' => null,
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$catid = (!empty($catid)) ? $db->escapeString(implode('|', $catid)) : "null";
|
||||
$this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings());
|
||||
}
|
||||
|
||||
$sql = sprintf("insert into usermovies (userid, imdbid, categoryid, createddate) values (%d, %d, %s, now())", $uid, $imdbid, $catid);
|
||||
return $db->queryInsert($sql);
|
||||
public function addMovie($uid, $imdbid, $catid= [])
|
||||
{
|
||||
|
||||
$catid = (!empty($catid)) ? $this->pdo->escapeString(implode('|', $catid)) : "null";
|
||||
|
||||
return $this->pdo->queryInsert(sprintf("INSERT INTO usermovies (userid, imdbid, categoryid, createddate) VALUES (%d, %d, %s, now())", $uid, $imdbid, $catid));
|
||||
}
|
||||
|
||||
public function getMovies($uid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$sql = sprintf("select usermovies.*, movieinfo.year, movieinfo.plot, movieinfo.cover, movieinfo.title from usermovies left outer join movieinfo on movieinfo.imdbid = usermovies.imdbid where userid = %d order by movieinfo.title asc", $uid);
|
||||
return $db->query($sql);
|
||||
return $this->pdo->query(sprintf("SELECT usermovies.*, movieinfo.year, movieinfo.plot, movieinfo.cover, movieinfo.title FROM usermovies LEFT OUTER JOIN movieinfo ON movieinfo.imdbid = usermovies.imdbid WHERE userid = %d ORDER BY movieinfo.title ASC", $uid));
|
||||
}
|
||||
|
||||
public function delMovie($uid, $imdbid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("DELETE from usermovies where userid = %d and imdbid = %d ", $uid, $imdbid));
|
||||
$this->pdo->queryExec(sprintf("DELETE FROM usermovies WHERE userid = %d AND imdbid = %d ", $uid, $imdbid));
|
||||
}
|
||||
|
||||
public function getMovie($uid, $imdbid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$sql = sprintf("select usermovies.*, movieinfo.title from usermovies left outer join movieinfo on movieinfo.imdbid = usermovies.imdbid where usermovies.userid = %d and usermovies.imdbid = %d ", $uid, $imdbid);
|
||||
return $db->queryOneRow($sql);
|
||||
return $this->pdo->queryOneRow(sprintf("SELECT usermovies.*, movieinfo.title FROM usermovies LEFT OUTER JOIN movieinfo ON movieinfo.imdbid = usermovies.imdbid WHERE usermovies.userid = %d AND usermovies.imdbid = %d ", $uid, $imdbid));
|
||||
}
|
||||
|
||||
public function delMovieForUser($uid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("DELETE from usermovies where userid = %d", $uid));
|
||||
$this->pdo->queryExec(sprintf("DELETE FROM usermovies WHERE userid = %d", $uid));
|
||||
}
|
||||
|
||||
public function updateMovie($uid, $imdbid, $catid=array())
|
||||
public function updateMovie($uid, $imdbid, $catid= [])
|
||||
{
|
||||
$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);
|
||||
$catid = (!empty($catid)) ? $this->pdo->escapeString(implode('|', $catid)) : "null";
|
||||
$this->pdo->queryExec(sprintf("UPDATE usermovies SET categoryid = %s WHERE userid = %d AND imdbid = %d", $catid, $uid, $imdbid));
|
||||
}
|
||||
}
|
||||
@@ -2,57 +2,67 @@
|
||||
|
||||
use newznab\db\Settings;
|
||||
|
||||
/**
|
||||
* Class UserSeries
|
||||
*/
|
||||
class UserSeries
|
||||
{
|
||||
public function addShow($uid, $rageid, $catid=array())
|
||||
/**
|
||||
* @var \newznab\db\Settings
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @param array $options Class instances.
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$db = new Settings();
|
||||
$defaults = [
|
||||
'Settings' => null,
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$catid = (!empty($catid)) ? $db->escapeString(implode('|', $catid)) : "null";
|
||||
$this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings());
|
||||
}
|
||||
|
||||
$sql = sprintf("insert into userseries (userid, rageid, categoryid, createddate) values (%d, %d, %s, now())", $uid, $rageid, $catid);
|
||||
return $db->queryInsert($sql);
|
||||
public function addShow($uid, $rageid, $catid= [])
|
||||
{
|
||||
|
||||
$catid = (!empty($catid)) ? $this->pdo->escapeString(implode('|', $catid)) : "null";
|
||||
|
||||
return $this->pdo->queryInsert(sprintf("INSERT INTO userseries (userid, rageid, categoryid, createddate) VALUES (%d, %d, %s, now())", $uid, $rageid, $catid));
|
||||
}
|
||||
|
||||
public function getShows($uid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$sql = sprintf("select userseries.*, tvrage.releasetitle from userseries inner join (SELECT id, releasetitle, rageid FROM tvrage GROUP BY rageid) tvrage on tvrage.rageid = userseries.rageid where userid = %d order by tvrage.releasetitle asc", $uid);
|
||||
return $db->query($sql);
|
||||
return $this->pdo->query(sprintf("SELECT userseries.*, tvrage.releasetitle FROM userseries INNER JOIN (SELECT id, releasetitle, rageid FROM tvrage GROUP BY rageid) tvrage ON tvrage.rageid = userseries.rageid WHERE userid = %d ORDER BY tvrage.releasetitle ASC", $uid));
|
||||
}
|
||||
|
||||
public function delShow($uid, $rageid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("DELETE from userseries where userid = %d and rageid = %d ", $uid, $rageid));
|
||||
$this->pdo->queryExec(sprintf("DELETE FROM userseries WHERE userid = %d AND rageid = %d ", $uid, $rageid));
|
||||
}
|
||||
|
||||
public function getShow($uid, $rageid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$sql = sprintf("select userseries.*, tvrage.releasetitle from userseries left outer join (SELECT id, releasetitle, rageid FROM tvrage GROUP BY rageid) tvrage on tvrage.rageid = userseries.rageid where userseries.userid = %d and userseries.rageid = %d ", $uid, $rageid);
|
||||
return $db->queryOneRow($sql);
|
||||
return $this->pdo->queryOneRow(sprintf("SELECT userseries.*, tvrage.releasetitle FROM userseries LEFT OUTER JOIN (SELECT id, releasetitle, rageid FROM tvrage GROUP BY rageid) tvrage ON tvrage.rageid = userseries.rageid WHERE userseries.userid = %d AND userseries.rageid = %d ", $uid, $rageid));
|
||||
}
|
||||
|
||||
public function delShowForUser($uid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("DELETE from userseries where userid = %d", $uid));
|
||||
$this->pdo->queryExec(sprintf("DELETE FROM userseries WHERE userid = %d", $uid));
|
||||
}
|
||||
|
||||
public function delShowForSeries($sid)
|
||||
{
|
||||
$db = new Settings();
|
||||
$db->queryExec(sprintf("DELETE from userseries where rageid = %d", $sid));
|
||||
$this->pdo->queryExec(sprintf("DELETE FROM userseries WHERE rageid = %d", $sid));
|
||||
}
|
||||
|
||||
public function updateShow($uid, $rageid, $catid=array())
|
||||
public function updateShow($uid, $rageid, $catid= [])
|
||||
{
|
||||
$db = new Settings();
|
||||
|
||||
$catid = (!empty($catid)) ? $db->escapeString(implode('|', $catid)) : "null";
|
||||
$catid = (!empty($catid)) ? $this->pdo->escapeString(implode('|', $catid)) : "null";
|
||||
|
||||
$sql = sprintf("update userseries set categoryid = %s where userid = %d and rageid = %d", $catid, $uid, $rageid);
|
||||
$db->queryExec($sql);
|
||||
$this->pdo->queryExec(sprintf("UPDATE userseries SET categoryid = %s WHERE userid = %d AND rageid = %d", $catid, $uid, $rageid));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user