Exemplo n.º 1
0
 public function addComment($id, $text, $userid, $host)
 {
     $db = new DB();
     $site = new Sites();
     $s = $site->get();
     if ($s->storeuserips != "1") {
         $host = "";
     }
     $comid = $db->queryInsert(sprintf("INSERT INTO releasecomment (`releaseID`, \t`text`, \t`userID`, \t`createddate`, \t`host`\t)\t\n\t\t\t\t\t\tVALUES (%d, \t%s, \t%d, \tnow(), \t%s\t)", $id, $db->escapeString($text), $userid, $db->escapeString($host)));
     $this->updateReleaseCommentCount($id);
     return $comid;
 }
Exemplo n.º 2
0
 public function update($form)
 {
     $db = new DB();
     $site = $this->row2Object($form);
     if (substr($site->nzbpath, strlen($site->nzbpath) - 1) != '/') {
         $site->nzbpath = $site->nzbpath . "/";
     }
     $sql = $sqlKeys = array();
     foreach ($form as $settingK => $settingV) {
         $sql[] = sprintf("WHEN %s THEN %s", $db->escapeString($settingK), $db->escapeString($settingV));
         $sqlKeys[] = $db->escapeString($settingK);
     }
     $db->query(sprintf("UPDATE site SET value = CASE setting %s END WHERE setting IN (%s)", implode(' ', $sql), implode(', ', $sqlKeys)));
     return $site;
 }
Exemplo n.º 3
0
 /**
  * Add a forum post.
  */
 public function add($parentid, $userid, $subject, $message, $locked = 0, $sticky = 0, $replies = 0)
 {
     $db = new DB();
     if ($message == "") {
         return -1;
     }
     if ($parentid != 0) {
         $par = $this->getParent($parentid);
         if ($par == false) {
             return -1;
         }
         $db->exec(sprintf("update forumpost set replies = replies + 1, updateddate = now() where ID = %d", $parentid));
     }
     $db->queryInsert(sprintf("INSERT INTO `forumpost` (`forumID`,`parentID`,`userID`,`subject`,`message`, `locked`, `sticky`, `replies`, `createddate`, `updateddate`) VALUES ( 1,  %d, %d,  %s,  %s, %d, %d, %d,NOW(),  NOW())", $parentid, $userid, $db->escapeString($subject), $db->escapeString($message), $locked, $sticky, $replies));
 }
Exemplo n.º 4
0
 public function updateMovie($uid, $imdbid, $catid = array())
 {
     $db = new DB();
     $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->query($sql);
 }
 public function updateShow($uid, $tvinfoid, $catid = array())
 {
     $db = new DB();
     $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null";
     $sql = sprintf("update userseries set categoryID = %s where userID = %d and tvinfoID = %d", $catid, $uid, $tvinfoid);
     $db->exec($sql);
 }
Exemplo n.º 6
0
 public function add($regex)
 {
     $db = new DB();
     $groupname = $regex["groupname"];
     if ($groupname == "") {
         $groupname = "null";
     } else {
         $groupname = sprintf("%s", $db->escapeString($regex["groupname"]));
     }
     $catid = $regex["category"];
     if ($catid == "-1") {
         $catid = "null";
     } else {
         $catid = sprintf("%d", $regex["category"]);
     }
     return $db->queryInsert(sprintf("insert into releaseregex (groupname, regex, ordinal, status, description, categoryID) values (%s, %s, %d, %d, %s, %s) ", $groupname, $db->escapeString($regex["regex"]), $regex["ordinal"], $regex["status"], $db->escapeString($regex["description"]), $catid));
 }
function generate()
{
    global $argv, $title;
    $db = new DB();
    $sphinx = new Sphinx();
    $sphinxDir = count($argv) > 2 ? rtrim($argv[2], '/') : "";
    $sphinxConf = count($argv) > 3 ? rtrim($argv[3], '/') : "";
    $sphinxConf = $sphinx->generateSphinxConf($sphinxDir, $sphinxConf);
    printf("Wrote configuration to: %s\n", $sphinxConf);
    $sql = sprintf("UPDATE site " . "SET value =  %s " . "WHERE  setting = 'sphinxconfpath'", $db->escapeString($sphinxConf));
    $db->exec($sql);
    return true;
}
Exemplo n.º 8
0
 public function update($form)
 {
     $db = new DB();
     $site = $this->row2Object($form);
     if (substr($site->nzbpath, strlen($site->nzbpath) - 1) != '/') {
         $site->nzbpath = $site->nzbpath . "/";
     }
     //
     // Validate site settings
     //
     if ($site->mediainfopath != "" && !is_file($site->mediainfopath)) {
         return Sites::ERR_BADMEDIAINFOPATH;
     }
     if ($site->ffmpegpath != "" && !is_file($site->ffmpegpath)) {
         return Sites::ERR_BADFFMPEGPATH;
     }
     if ($site->unrarpath != "" && !is_file($site->unrarpath)) {
         return Sites::ERR_BADUNRARPATH;
     }
     if ($site->nzbpath != "" && !file_exists($site->nzbpath)) {
         return Sites::ERR_BADNZBPATH;
     }
     if ($site->checkpasswordedrar == 2 && !is_file($site->unrarpath)) {
         return Sites::ERR_DEEPNOUNRAR;
     }
     if ($site->tmpunrarpath != "" && !file_exists($site->tmpunrarpath)) {
         return Sites::ERR_BADTMPUNRARPATH;
     }
     $sql = $sqlKeys = array();
     foreach ($form as $settingK => $settingV) {
         $sql[] = sprintf("WHEN %s THEN %s", $db->escapeString($settingK), $db->escapeString($settingV));
         $sqlKeys[] = $db->escapeString($settingK);
     }
     $db->query(sprintf("UPDATE site SET value = CASE setting %s END WHERE setting IN (%s)", implode(' ', $sql), implode(', ', $sqlKeys)));
     return $site;
 }
     }
 }
 $groups = $db->query("SELECT ID, name FROM groups");
 foreach ($groups as $group) {
     $siteGroups[$group["name"]] = $group["ID"];
 }
 if (!isset($groups) || count($groups) == 0) {
     $retval .= "no groups available in the database, add first.<br/>";
 } else {
     foreach ($filestoprocess as $nzbFile) {
         $nzbInfo = new nzbInfo();
         if (!$nzbInfo->loadFromFile($nzbFile, true)) {
             $retval .= "Failed to load NZB : " . $browserpostednames[$nzbFile] . "<br/>";
             continue;
         } else {
             $dupes = $db->queryOneRow(sprintf("SELECT EXISTS(SELECT 1 FROM releases WHERE gid = %s) as total", $db->escapeString($nzbInfo->gid)));
             if ($dupes['total'] > 0) {
                 $retval .= "Duplicate NZB : " . $browserpostednames[$nzbFile] . "<br/>";
                 continue;
             } else {
                 $groupID = -1;
                 foreach ($nzbInfo->groups as $group) {
                     $group = (string) $group;
                     if (array_key_exists($group, $siteGroups)) {
                         $groupID = $siteGroups[$group];
                         $groupName = $group;
                         break;
                     }
                 }
                 if ($groupID == -1) {
                     $retval .= "Missing Group for NZB : " . $browserpostednames[$nzbFile] . " - " . join(", ", $nzbInfo->groups) . "<br/>";
Exemplo n.º 10
0
function updateMusicInfo($artist, $album, $year)
{
    $db = new DB();
    $gen = new Genres();
    $music = new Music();
    $mus = array();
    $amaz = $music->fetchAmazonProperties($artist . " - " . $album);
    if (!$amaz) {
        return false;
    }
    //load genres
    $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE);
    $genreassoc = array();
    foreach ($defaultGenres as $dg) {
        $genreassoc[$dg['ID']] = strtolower($dg['title']);
    }
    //
    // get album properties
    //
    $mus['coverurl'] = (string) $amaz->Items->Item->MediumImage->URL;
    if ($mus['coverurl'] != "") {
        $mus['cover'] = 1;
    } else {
        $mus['cover'] = 0;
    }
    $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
    if (empty($mus['title'])) {
        $mus['title'] = $album;
    }
    $mus['asin'] = (string) $amaz->Items->Item->ASIN;
    $mus['url'] = (string) $amaz->Items->Item->DetailPageURL;
    $mus['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $mus['url']);
    $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank;
    if ($mus['salesrank'] == "") {
        $mus['salesrank'] = 'null';
    }
    $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist;
    if (empty($mus['artist'])) {
        $mus['artist'] = $artist;
    }
    $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
    $mus['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
    if ($mus['releasedate'] == "''") {
        $mus['releasedate'] = 'null';
    }
    $mus['review'] = "";
    if (isset($amaz->Items->Item->EditorialReviews)) {
        $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
    }
    $mus['year'] = $year;
    if ($mus['year'] == "" && $mus['releasedate'] != 'null') {
        $mus['year'] = substr($mus['releasedate'], 1, 4);
    }
    $mus['tracks'] = "";
    if (isset($amaz->Items->Item->Tracks)) {
        $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc;
        $tracks = $tmpTracks['Track'];
        $mus['tracks'] = is_array($tracks) && !empty($tracks) ? implode('|', $tracks) : '';
    }
    $genreKey = -1;
    $genreName = '';
    $amazGenres = (array) $amaz->Items->Item->BrowseNodes;
    foreach ($amazGenres as $amazGenre) {
        foreach ($amazGenre as $ag) {
            $tmpGenre = strtolower((string) $ag->Name);
            if (!empty($tmpGenre)) {
                if (in_array($tmpGenre, $genreassoc)) {
                    $genreKey = array_search($tmpGenre, $genreassoc);
                    $genreName = $tmpGenre;
                    break;
                } else {
                    //we got a genre but its not stored in our genre table
                    $genreName = (string) $ag->Name;
                    $genreKey = 'new genre to be added';
                    //$genreKey = $db->queryInsert(sprintf("INSERT INTO genres (`title`, `type`) VALUES (%s, %d)", $db->escapeString($genreName), Genres::MUSIC_TYPE));
                    break;
                }
            }
        }
    }
    $mus['musicgenre'] = $genreName;
    $mus['musicgenreID'] = $genreKey;
    $mus['amaz'] = $amaz->Items->Item;
    return $mus;
}
Exemplo n.º 11
0
 public function update($menu)
 {
     $db = new DB();
     return $db->query(sprintf("update menu set href = %s, title = %s, tooltip = %s, role = %d, ordinal = %d, menueval = %s, newwindow=%d where ID = %d\t", $db->escapeString($menu["href"]), $db->escapeString($menu["title"]), $db->escapeString($menu["tooltip"]), $menu["role"], $menu["ordinal"], $db->escapeString($menu["menueval"]), $menu["newwindow"], $menu["id"]));
 }
 public function fetchTestBinaries($groupname, $numarticles, $clearexistingbins)
 {
     $db = new DB();
     $nntp = new Nntp();
     $binaries = new Binaries();
     $groups = new Groups();
     $ret = array();
     if ($clearexistingbins == true) {
         $db->exec('truncate releaseregextesting');
     }
     $nntp->doConnect();
     $groupsToFetch = array();
     if (preg_match('/^[a-z]{2,3}(\\.[a-z0-9\\-]+)+$/', $groupname)) {
         $groupsToFetch[] = array('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']);
             }
         }
     }
     foreach ($groupsToFetch as $groupArr) {
         $group = $groupArr['name'];
         $data = $nntp->selectGroup($group);
         if ($nntp->isError($data)) {
             $ret[] = "Could not select group (doesnt exist on USP): {$group}";
             continue;
         } else {
             $rangeStart = $data['last'] - $numarticles;
             $rangeEnd = $groupEnd = $data['last'];
             $rangeTotal = $rangeEnd - $rangeStart;
             $done = false;
             while ($done === false) {
                 if ($rangeTotal > $binaries->messagebuffer) {
                     if ($rangeStart + $binaries->messagebuffer > $groupEnd) {
                         $rangeEnd = $groupEnd;
                     } else {
                         $rangeEnd = $rangeStart + $binaries->messagebuffer;
                     }
                 }
                 if ($binaries->compressedHeaders) {
                     $msgs = $nntp->getXOverview($rangeStart . "-" . $rangeEnd, true, false);
                 } else {
                     $msgs = $nntp->getOverview($rangeStart . "-" . $rangeEnd, true, false);
                 }
                 if ($nntp->isError($msgs)) {
                     $ret[] = "Error {$msgs->code}: {$msgs->message} on " . $group;
                     continue 2;
                 }
                 $headers = array();
                 if (is_array($msgs)) {
                     //loop headers, figure out parts
                     foreach ($msgs as $msg) {
                         if (!isset($msg['Number'])) {
                             continue;
                         }
                         $msgPart = $msgTotalParts = 0;
                         $pattern = '|\\((\\d+)[\\/](\\d+)\\)|i';
                         preg_match_all($pattern, $msg['Subject'], $matches, PREG_PATTERN_ORDER);
                         $matchcnt = sizeof($matches[0]);
                         for ($i = 0; $i < $matchcnt; $i++) {
                             //not (int)'d here because of the preg_replace later on
                             $msgPart = $matches[1][$i];
                             $msgTotalParts = $matches[2][$i];
                         }
                         if (!isset($msg['Subject']) || $matchcnt == 0) {
                             // not a binary post most likely.. continue
                             continue;
                         }
                         if ((int) $msgPart > 0 && (int) $msgTotalParts > 0) {
                             $subject = utf8_encode(trim(preg_replace('|\\(' . $msgPart . '[\\/]' . $msgTotalParts . '\\)|i', '', $msg['Subject'])));
                             if (!isset($headers[$subject])) {
                                 $headers[$subject]['Subject'] = $subject;
                                 $headers[$subject]['From'] = $msg['From'];
                                 $headers[$subject]['Date'] = strtotime($msg['Date']);
                                 $headers[$subject]['Message-ID'] = $msg['Message-ID'];
                                 $headers[$subject]['Size'] = $msg['Bytes'];
                             } else {
                                 $headers[$subject]['Size'] += $msg['Bytes'];
                             }
                         }
                     }
                     unset($msgs);
                     if (isset($headers) && count($headers)) {
                         $groupRegexes = $this->getForGroup($group);
                         $binSetData = array();
                         foreach ($headers as $subject => $data) {
                             $binData = array('name' => $subject, 'fromname' => $data['From'], 'date' => $data['Date'], 'binaryhash' => md5($subject . $data['From'] . $group), 'groupname' => $group, 'regexID' => "null", 'categoryID' => "null", 'reqID' => "null", 'blacklistID' => 0, 'size' => $data['Size'], 'relname' => "null", 'relpart' => "null", 'reltotalpart' => "null");
                             //Filter binaries based on black/white list
                             if ($binaries->isBlackListed($data, $group)) {
                                 //binary is blacklisted
                                 $binData['blacklistID'] = 1;
                             }
                             //Apply Regexes
                             $regexMatches = array();
                             foreach ($groupRegexes as $groupRegex) {
                                 $regexCheck = $this->performMatch($groupRegex, $subject, $data['From']);
                                 if ($regexCheck !== false) {
                                     $regexMatches = $regexCheck;
                                     $binData['regexID'] = $regexCheck['regexID'];
                                     $binData['categoryID'] = $regexCheck['regcatid'];
                                     $binData['reqID'] = empty($regexCheck['reqID']) ? "null" : $regexCheck['reqID'];
                                     $binData['relname'] = $regexCheck['name'];
                                     break;
                                 }
                             }
                             $binSetData[] = $binData;
                         }
                         //insert 500 bins at a time
                         $binChunks = array_chunk($binSetData, 500);
                         foreach ($binChunks as $binChunk) {
                             foreach ($binChunk as $chunk) {
                                 $binParams[] = sprintf("(%s, %s, FROM_UNIXTIME(%s), %s, %s, %s, %s, %s, %d, %d, now())", $db->escapeString($chunk['name']), $db->escapeString($chunk['fromname']), $db->escapeString($chunk['date']), $db->escapeString($chunk['binaryhash']), $db->escapeString($chunk['groupname']), $chunk['regexID'], $chunk['categoryID'], $chunk['reqID'], $chunk['blacklistID'], $chunk['size']);
                             }
                             $binSql = "INSERT IGNORE INTO releaseregextesting (name, fromname, date, binaryhash, groupname, regexID, categoryID, reqID, blacklistID, size, dateadded) VALUES " . implode(', ', $binParams);
                             //echo $binSql;
                             $db->exec($binSql);
                         }
                         $ret[] = "Fetched " . number_format($numarticles) . " articles from " . $group;
                     } else {
                         $ret[] = "No headers found on " . $group;
                         continue;
                     }
                 } else {
                     $ret[] = "Can't get parts from server (msgs not array) on " . $group;
                     continue;
                 }
                 if ($rangeEnd == $groupEnd) {
                     $done = true;
                 }
                 $rangeStart = $rangeEnd + 1;
             }
         }
     }
     $nntp->doQuit();
     return $ret;
 }
Exemplo n.º 13
0
<?php

if (!isset($_GET['id']) || empty($_GET['id'])) {
    die("Please first select a lesson!");
}
$lessonId = htmlspecialchars($_GET['id']);
$lessonId = DB::escapeString($lessonId);
$lesson = Lesson::getLesson($lessonId);
$course = Course::getCourseById($lesson->getCourseId());
if (!isset($lesson)) {
    die("This lesson was not found!");
}
$courseId = $lesson->getCourseId();
$filePath = PAGE_DIR . "lessons/{$courseId}-{$lessonId}.html";
$exerciseComponent = '<div class="well ui">
    <form action="' . ROOT_DIR . 'exercises/' . $lessonId . '" method="post">
      <button type="submit" class="btn btn-default btn-block">' . I18n::t('lesson.startexercises') . '</button>
    </form>
  </div>';
// display content
echo '<ol class="breadcrumb">
                <li><a href="' . ROOT_DIR . 'courseoverview">' . I18n::t('courseoverview.title') . '</a></li>
                <li><a href="' . ROOT_DIR . 'course/' . $course->getId() . '">' . $course->getName(I18n::getLang()) . '</a></li>
                <li class="active">' . $lesson->getName(I18n::getLang()) . '</li>
              </ol>';
echo $exerciseComponent;
echo '<h1>' . $lesson->getName(I18n::getLang()) . '</h1>';
if (file_exists($filePath) && filesize($filePath) > 1) {
    echo '<h2>Tutorial</h2>';
    echo file_get_contents($filePath);
    echo $exerciseComponent;
 /**
  * Update a category.
  */
 public function update($id, $status, $desc, $disablepreview, $minsize, $maxsize)
 {
     $db = new DB();
     return $db->exec(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));
 }
Exemplo n.º 15
0
 public function update($id, $status, $desc)
 {
     $db = new DB();
     return $db->query(sprintf("update category set status = %d, description = %s where ID = %d", $status, $db->escapeString($desc), $id));
 }
Exemplo n.º 16
0
 public function updateItem($setting, $value)
 {
     $db = new DB();
     $sql = sprintf("update site set value = %s where setting = %s", $db->escapeString($value), $db->escapeString($setting));
     return $db->exec($sql);
 }
Exemplo n.º 17
0
 protected function secureString($string)
 {
     $string = htmlspecialchars($string);
     return DB::escapeString($string);
 }
Exemplo n.º 18
0
 public function addApiRequest($userid, $request)
 {
     $db = new DB();
     $sql = sprintf("insert into userrequests (userID, request, timestamp) VALUES (%d, %s, now())", $userid, $db->escapeString($request));
     return $db->queryInsert($sql);
 }
 /**
  * Add a releasefiles row.
  */
 public function add($id, $name, $size, $createddate, $passworded)
 {
     $db = new DB();
     $sql = sprintf("INSERT INTO releasefiles (releaseID, name, extension, size, createddate, passworded) VALUES (%d, %s, LOWER(SUBSTRING_INDEX(name,'.',-1)), %s, from_unixtime(%d), %d)", $id, $db->escapeString($name), $db->escapeString($size), $createddate, $passworded);
     return $db->queryInsert($sql);
 }
Exemplo n.º 20
0
    public function addEpisode($tvdbid, $mazeid, $showtitle, $airdate, $season, $episode, $eptitle, $director, $gueststars, $overview, $rating, $writer, $epabsolute, $tvinfoid)
    {
        $db = new DB();
        $sql = sprintf('INSERT INTO episodeinfo
			(tvdbID, mazeID, showtitle, airdate, fullep, eptitle, director, gueststars, overview, rating, writer, epabsolute, tvinfoID)
			VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %F, %s, %s, %d)
			ON DUPLICATE KEY UPDATE
			tvdbID=%1$s, mazeID=%2$s, showtitle=%3$s, airdate=%4$s, fullep=%5$s, eptitle=%6$s, director=%7$s,
			gueststars=%8$s, overview=%9$s, rating=%10$F, writer=%11$s, epabsolute=%12$s', $db->nullInt($tvdbid), $db->nullInt($mazeid), $db->escapeString($showtitle), $db->escapeString($airdate), $db->escapeString(str_pad($season, 2, '0', STR_PAD_LEFT) . 'x' . str_pad($episode, 2, '0', STR_PAD_LEFT)), $db->escapeString($eptitle), $db->escapeString($director), $db->escapeString($gueststars), $db->escapeString(substr($overview, 0, 10000)), $rating, $db->escapeString($writer), $db->nullInt($epabsolute), $tvinfoid);
        return $db->queryInsert($sql);
    }
Exemplo n.º 21
0
<?php

require_once 'config.php';
$nickname = htmlspecialchars($_POST['nickname']);
$nickname = DB::escapeString($nickname);
if (User::nicknameIsRegistered($nickname)) {
    echo 'true';
} else {
    echo 'false';
}
Exemplo n.º 22
0
 public function updateMusicInfo($artist, $album, $year)
 {
     $db = new DB();
     $gen = new Genres();
     $ri = new ReleaseImage();
     $mus = array();
     $amaz = $this->fetchAmazonProperties($artist . " - " . $album);
     if (!$amaz) {
         return false;
     }
     //load genres
     $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE);
     $genreassoc = array();
     foreach ($defaultGenres as $dg) {
         $genreassoc[$dg['ID']] = strtolower($dg['title']);
     }
     //
     // get album properties
     //
     $mus['coverurl'] = (string) $amaz->Items->Item->MediumImage->URL;
     if ($mus['coverurl'] != "") {
         $mus['cover'] = 1;
     } else {
         $mus['cover'] = 0;
     }
     $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
     if (empty($mus['title'])) {
         $mus['title'] = $album;
     }
     $mus['asin'] = (string) $amaz->Items->Item->ASIN;
     $mus['url'] = (string) $amaz->Items->Item->DetailPageURL;
     $mus['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $mus['url']);
     $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank;
     if ($mus['salesrank'] == "") {
         $mus['salesrank'] = 'null';
     }
     $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist;
     if (empty($mus['artist'])) {
         $mus['artist'] = $artist;
     }
     $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
     $mus['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
     if ($mus['releasedate'] == "''") {
         $mus['releasedate'] = 'null';
     }
     $mus['review'] = "";
     if (isset($amaz->Items->Item->EditorialReviews)) {
         $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
     }
     $mus['year'] = $year;
     if ($mus['year'] == "") {
         $mus['year'] = $mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y");
     }
     $mus['tracks'] = "";
     if (isset($amaz->Items->Item->Tracks)) {
         $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc;
         $tracks = $tmpTracks['Track'];
         $mus['tracks'] = is_array($tracks) && !empty($tracks) ? implode('|', $tracks) : '';
     }
     //This is to verify the result back from amazon was at least somewhat related to what was intended.
     //If you are debugging releases comment out the following code to show all info
     $match = similar_text($artist, $mus['artist'], $artistpercent);
     //echo("Matched: Artist Percentage: $artistpercent%");
     $match = similar_text($album, $mus['title'], $albumpercent);
     //echo("Matched: Album Percentage: $albumpercent%");
     //If the artist is Various Artists, assume artist is 100%
     if (preg_match('/various/i', $artist)) {
         $artistpercent = '100';
     }
     //If the Artist is less than 80% album must be 100%
     if ($artistpercent < '80') {
         if ($albumpercent != '100') {
             return false;
         }
     }
     //If the album is ever under 30%, it's probably not a match.
     if ($albumpercent < '30') {
         return false;
     }
     //This is the end of the recheck code. Comment out to this point to show all info.
     $genreKey = -1;
     $genreName = '';
     if (isset($amaz->Items->Item->BrowseNodes)) {
         //had issues getting this out of the browsenodes obj
         //workaround is to get the xml and load that into its own obj
         $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml();
         $amazGenresObj = simplexml_load_string($amazGenresXml);
         $amazGenres = $amazGenresObj->xpath("//BrowseNodeId");
         foreach ($amazGenres as $amazGenre) {
             $currNode = trim($amazGenre[0]);
             if (empty($genreName)) {
                 $genreMatch = $this->matchBrowseNode($currNode);
                 if ($genreMatch !== false) {
                     $genreName = $genreMatch;
                     break;
                 }
             }
         }
         if (in_array(strtolower($genreName), $genreassoc)) {
             $genreKey = array_search(strtolower($genreName), $genreassoc);
         } else {
             $genreKey = $db->queryInsert(sprintf("INSERT INTO genres (`title`, `type`) VALUES (%s, %d)", $db->escapeString($genreName), Genres::MUSIC_TYPE));
         }
     }
     $mus['musicgenre'] = $genreName;
     $mus['musicgenreID'] = $genreKey;
     $query = 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()", $db->escapeString($mus['title']), $db->escapeString($mus['asin']), $db->escapeString($mus['url']), $mus['salesrank'], $db->escapeString($mus['artist']), $db->escapeString($mus['publisher']), $mus['releasedate'], $db->escapeString($mus['review']), $db->escapeString($mus['year']), $mus['musicgenreID'] == -1 ? "null" : $mus['musicgenreID'], $db->escapeString($mus['tracks']), $mus['cover'], $db->escapeString($mus['title']), $db->escapeString($mus['asin']), $db->escapeString($mus['url']), $mus['salesrank'], $db->escapeString($mus['artist']), $db->escapeString($mus['publisher']), $mus['releasedate'], $db->escapeString($mus['review']), $db->escapeString($mus['year']), $mus['musicgenreID'] == -1 ? "null" : $mus['musicgenreID'], $db->escapeString($mus['tracks']), $mus['cover']);
     $musicId = $db->queryInsert($query);
     if ($musicId) {
         if ($this->echooutput) {
             echo "added/updated album: " . $mus['title'] . " (" . $mus['year'] . ")\n";
         }
         $mus['cover'] = $ri->saveImage($musicId, $mus['coverurl'], $this->imgSavePath, 250, 250);
     } else {
         if ($this->echooutput) {
             echo "nothing to update: " . $mus['title'] . " (" . $mus['year'] . ")\n";
         }
     }
     return $musicId;
 }
Exemplo n.º 23
0
 /**
  * Insert or update a musicinfo row.
  */
 public function addUpdateMusicInfo($title, $asin, $url, $salesrank, $artist, $publisher, $releasedate, $review, $year, $genreID, $tracks, $cover)
 {
     $db = new DB();
     if (strlen($year) > 4) {
         if (preg_match("/\\d{4}/", $year, $matches)) {
             $year = $db->escapeString($matches[0]);
         } else {
             $year = "null";
         }
     } else {
         $year = $db->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()", $db->escapeString($title), $db->escapeString($asin), $db->escapeString($url), $salesrank, $db->escapeString($artist), $db->escapeString($publisher), $releasedate, $db->escapeString($review), $year, $genreID == -1 ? "null" : $genreID, $db->escapeString($tracks), $cover, $db->escapeString($title), $db->escapeString($asin), $db->escapeString($url), $salesrank, $db->escapeString($artist), $db->escapeString($publisher), $releasedate, $db->escapeString($review), $db->escapeString($year), $genreID == -1 ? "null" : $genreID, $db->escapeString($tracks), $cover);
     $musicId = $db->queryInsert($sql);
     return $musicId;
 }
Exemplo n.º 24
0
 public function processMovieReleases()
 {
     $ret = 0;
     $db = new DB();
     $nfo = new Nfo();
     $res = $db->queryDirect(sprintf("SELECT searchname, ID from releases where imdbID IS NULL and categoryID in ( select ID from category where parentID = %d )", Category::CAT_PARENT_MOVIE));
     if (mysql_num_rows($res) > 0) {
         if ($this->echooutput) {
             echo "Processing " . mysql_num_rows($res) . " movie releases\n";
         }
         while ($arr = mysql_fetch_assoc($res)) {
             $moviename = $this->parseMovieName($arr['searchname']);
             if ($moviename !== false) {
                 if ($this->echooutput) {
                     echo 'Looking up: ' . $moviename . ' [' . $arr['searchname'] . ']' . "\n";
                 }
                 $buffer = getUrl("http://www.google.com/search?source=ig&hl=en&rlz=&btnG=Google+Search&aq=f&oq=&q=" . urlencode($moviename . ' imdb'));
                 // make sure we got some data
                 if ($buffer !== false && strlen($buffer)) {
                     $imdbId = $nfo->parseImdb($buffer);
                     if ($imdbId !== false) {
                         if ($this->echooutput) {
                             echo '- found ' . $imdbId . "\n";
                         }
                         //update release with imdb id
                         $db->query(sprintf("UPDATE releases SET imdbID = %s WHERE ID = %d", $db->escapeString($imdbId), $arr["ID"]));
                         //check for existing movie entry
                         $movCheck = $this->getMovieInfo($imdbId);
                         if ($movCheck === false || isset($movCheck['updateddate']) && time() - strtotime($movCheck['updateddate']) > 2592000) {
                             $movieId = $this->updateMovieInfo($imdbId);
                         }
                     } else {
                         //no imdb id found, set to all zeros so we dont process again
                         $db->query(sprintf("UPDATE releases SET imdbID = %d WHERE ID = %d", 0, $arr["ID"]));
                     }
                 } else {
                     //url fetch failed, will try next run
                 }
             } else {
                 //no valid movie name found, set to all zeros so we dont process again
                 $db->query(sprintf("UPDATE releases SET imdbID = %d WHERE ID = %d", 0, $arr["ID"]));
             }
         }
     }
 }
Exemplo n.º 25
0
 /**
  * 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->exec(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;
 }
Exemplo n.º 26
0
 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();
     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", $id, $uid);
             $res = $db->exec($query);
             if ($this->verbose) {
                 echo "s";
             }
         }
     }
     // 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 ($res <= 0) {
             if ($this->verbose) {
                 echo "!";
             }
         } else {
             if ($this->verbose) {
                 echo "s";
             }
         }
     }
 }
Exemplo n.º 27
0
 public function processTvReleases($lookupTvRage = true)
 {
     $ret = 0;
     $db = new DB();
     // get all releases without a rageid which are in a tv category.
     $result = $db->queryDirect(sprintf("SELECT searchname, ID from releases where rageID = -1 and categoryID in ( select ID from category where parentID = %d )", Category::CAT_PARENT_TV));
     if ($this->echooutput) {
         echo "Processing tv for " . mysql_num_rows($result) . " releases\n";
         echo "Lookup tv rage from the web - " . ($lookupTvRage ? "Yes\n" : "No\n");
     }
     while ($arr = mysql_fetch_assoc($result)) {
         $show = $this->parseNameEpSeason($arr['searchname']);
         if (is_array($show) && $show['name'] != '') {
             // update release with season, ep, and airdate info (if available) from releasetitle
             $this->updateEpInfo($show, $arr['ID']);
             // find the rageID
             $id = $this->getByTitle($show['cleanname']);
             if ($id === false && $lookupTvRage) {
                 // if it doesnt exist locally and lookups are allowed lets try to get it
                 if ($this->echooutput) {
                     echo 'didnt find rageid for "' . $show['cleanname'] . '" in local db, checking web...' . "\n";
                 }
                 $tvrShow = $this->getRageMatch($show);
                 if ($tvrShow !== false && is_array($tvrShow)) {
                     // get all tv info and add show
                     $this->updateRageInfo($tvrShow['showid'], $show, $tvrShow, $arr['ID']);
                 } elseif ($tvrShow === false) {
                     // no match
                     //add to tvrage with rageID = -2 and $show['cleanname'] title only
                     $this->add(-2, $show['cleanname'], '', '', '', '');
                 } else {
                     // $tvrShow probably equals -1 but we'll do this as a catchall instead of a specific elseif
                     //skip because we couldnt connect to tvrage.com
                 }
             } elseif ($id > 0) {
                 $tvairdate = isset($show['airdate']) && !empty($show['airdate']) ? $db->escapeString($show['airdate']) : "null";
                 $tvtitle = "null";
                 if ($lookupTvRage) {
                     $epinfo = $this->getEpisodeInfo($id, $show['season'], $show['episode']);
                     if ($epinfo !== false) {
                         if (!empty($epinfo['airdate'])) {
                             $tvairdate = $db->escapeString($epinfo['airdate']);
                         }
                         if (!empty($epinfo['title'])) {
                             $tvtitle = $db->escapeString($epinfo['title']);
                         }
                     }
                 }
                 $db->query(sprintf("update releases set tvtitle=trim(%s), tvairdate=%s, rageID = %d where ID = %d", $tvtitle, $tvairdate, $id, $arr["ID"]));
             } else {
                 // cant find rageid, so set rageid to n/a
                 $db->query(sprintf("update releases set rageID = -2 where ID = %d", $arr["ID"]));
             }
         } else {
             // not a tv episode, so set rageid to n/a
             $db->query(sprintf("update releases set rageID = -2 where ID = %d", $arr["ID"]));
         }
         $ret++;
     }
     return $ret;
 }
Exemplo n.º 28
0
 /**
  * Get predb rows by limit and filter.  This presents the same interface as
  * :php:meth:`PreDB::getPreRange`.
  */
 public function getPreRange($start = 0, $num, $dirname = '', $category = '')
 {
     $db = new DB();
     $dirname = empty($category) ? $dirname : $dirname . " @category =" . $category;
     $sphinxQuery = sprintf("SELECT id " . "FROM predb, predb_delta " . "WHERE MATCH(%s) " . "ORDER BY ctime DESC " . "LIMIT %d,%d", $db->escapeString($dirname), $start, $num);
     $lookupQuery = "SELECT predb.*, r.guid " . "FROM predb " . "LEFT OUTER JOIN releases r " . "ON r.preID = predb.ID " . "WHERE predb.ID IN (%s) " . "ORDER BY predb.ctime DESC";
     return $this->searchDirect($sphinxQuery, $lookupQuery, 120);
 }
Exemplo n.º 29
0
 public function data_add($content)
 {
     $db = new DB();
     return $db->queryInsert(sprintf("insert into content (role, title, url, body, metadescription, metakeywords, \tcontenttype, \tshowinmenu, \tstatus, \tordinal\t)\tvalues\t(%d, %s, \t%s, \t%s, \t%s, \t%s, \t%d, \t%d, \t%d, \t%d \t)", $content->role, $db->escapeString($content->title), $db->escapeString($content->url), $db->escapeString($content->body), $db->escapeString($content->metadescription), $db->escapeString($content->metakeywords), $content->contenttype, $content->showinmenu, $content->status, $content->ordinal));
 }
Exemplo n.º 30
0
 public function addFull($id, $xml)
 {
     $db = new DB();
     return $db->queryInsert(sprintf("insert into releaseextrafull (releaseID, mediainfo) values (%d, %s)", $id, $db->escapeString($xml)));
 }